﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;





namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Clear chart & basic chart settings.
            for (int i = 0; i < chart2.Series.Count; i++)
            {
                chart2.Series[i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
                chart2.Series[i].LegendText = "-";
                chart2.Series[i].Points.Clear();
            }


            Globals.LIMIT_BINDING_SITE_CAPACITY = checkBoxKapacitetaOmejena.Checked;

            if (radioButton1.Checked)
            {
                Globals.TRANSCRIPTION_MODEL = 1;
            }
            if (radioButton2.Checked)
            {
                Globals.TRANSCRIPTION_MODEL = 2;
            }

            
                    // test, kakšne vrednosti dobimo z modelom 2 transkripcije (posnemanje hillovih enačb z n=1 - brez kooperativnosti)
                    /*using (StreamWriter writer = new StreamWriter("C:\\Users\\Dusan\\Desktop\\hill.txt"))
                    {
                        // transcription rate = 100 (fiksna stevilka v enacbah spodaj)
                        int Ka = 25;
                        int Kr = 25;

                        writer.Write("aktivacija = [");
                        for (int a = 0; a < 1000; a++)
                        {
                            int f_act = (int)Math.Round(((double)100 * (double)a) / ((double)Ka + (double)a));
                            writer.Write(f_act + " ");
                        }
                        writer.Write("];");

                        writer.WriteLine(); writer.WriteLine();

                        writer.Write("represija = [");
                        for (int r = 0; r < 1000; r++)
                        {
                            int f_rep = (int)Math.Round(((double)100 * (double)Kr) / ((double)Kr + (double)r));
                            writer.Write(f_rep + " ");
                        }
                        writer.Write("];");
                    }*/
                         

        }



        // Save simulation plot (chart) as an image.
        private void button2_Click(object sender, EventArgs e)
        {
            chart2.SaveImage(textBox5.Text, System.Drawing.Imaging.ImageFormat.Png);
            MessageBox.Show("Image saved.");
        }


        //========== GENETIC TOGGLE SWITCH (Gardner, Bistabilno stikalo) ==========//        
        private void button1_Click(object sender, EventArgs e)
        {
            Globals.SIMULATION_TIME = 500;

            // Plot settings
            chart2.ChartAreas[0].AxisY.LabelStyle.Interval = 10;

            for (int i = 0; i < chart2.Series.Count; i++)
            {
                chart2.Series[i].Points.Clear();
                chart2.Series[i].LegendText = "-";
            }            
            
            chart2.Series[0].LegendText = "LacI mRNA";
            chart2.Series[0].Color = Color.FromArgb(200, 225, 0, 0);
            chart2.Series[0].BorderWidth = 2;
            chart2.Series[0].Points.AddXY(0, 0);

            chart2.Series[1].LegendText = "LacI Protein";
            chart2.Series[1].Color = Color.FromArgb(120, 255, 200, 0);
            chart2.Series[1].BorderWidth = 2;
            chart2.Series[1].Points.AddXY(0, 0);

            chart2.Series[2].LegendText = "cIts mRNA";
            chart2.Series[2].Color = Color.FromArgb(200, 0, 0, 225);
            chart2.Series[2].BorderWidth = 2;
            chart2.Series[2].Points.AddXY(0, 0);

            chart2.Series[3].LegendText = "cIts Protein";
            chart2.Series[3].Color = Color.FromArgb(170, 0, 0, 255);
            chart2.Series[3].BorderWidth = 2;
            chart2.Series[3].Points.AddXY(0, 0);

            chart2.Series[4].LegendText = "GFP mRNA";
            chart2.Series[4].Color = Color.FromArgb(40, 0, 225, 0);
            chart2.Series[4].BorderWidth = 2;
            chart2.Series[4].Points.AddXY(0, 0);

            chart2.Series[5].LegendText = "GFP Protein";
            chart2.Series[5].Color = Color.FromArgb(90, 0, 255, 0);
            chart2.Series[5].BorderWidth = 3;
            chart2.Series[5].Points.AddXY(0, 0);
            //chart2.Series[5].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
            
           
            // Molecules lists
            List<Protein> cits_proteins = new List<Protein>();
            List<Protein> laci_proteins = new List<Protein>();
            List<Protein> gfp_proteins = new List<Protein>();

            List<MRNA> cits_mRNAs = new List<MRNA>();
            List<MRNA> laci_mRNAs = new List<MRNA>();
            List<MRNA> gfp_mRNAs = new List<MRNA>();



            // laci gene promoter            
            List<RepressorBindingSite> laci_repr_bind_sites = new List<RepressorBindingSite>();                
            RepressorBindingSite laci_rbs1 = new RepressorBindingSite();
            laci_rbs1.MaxCapacity = 35;
            laci_repr_bind_sites.Add(laci_rbs1);

                //List<ActivatorBindingSite> laci_act_bind_sites = new List<ActivatorBindingSite>();
                //ActivatorBindingSite laci_abs1 = new ActivatorBindingSite();
                //laci_act_bind_sites.Add(laci_abs1);

            Promoter Promoter1 = new Promoter();
            Promoter1.Enabled = true;
            Promoter1.Type = PromoterType.Constitutive;            
            Promoter1.Strength = 1;           
            Promoter1.RepressorBindSitesList = laci_repr_bind_sites;
            //Promoter1.ActivatorBindSitesList = laci_act_bind_sites;


            // cits & GFP promoter
            List<RepressorBindingSite> cits_repr_bind_sites = new List<RepressorBindingSite>();
            RepressorBindingSite cits_rbs1 = new RepressorBindingSite();
            cits_rbs1.MaxCapacity = 35;
            cits_repr_bind_sites.Add(cits_rbs1);

            Promoter Promoter2 = new Promoter();
            Promoter2.Enabled = true;
            Promoter2.Type = PromoterType.Constitutive;
            Promoter2.Strength = 1;
            Promoter2.RepressorBindSitesList = cits_repr_bind_sites;



            // laci gene
            GeneExpression laciProduction = new GeneExpression();            
            laciProduction.GenePromoter = Promoter1;
            laciProduction.TranscriptionRate = 10;
            laciProduction.TranslationRate = 1;
            laciProduction.mRNADegradationPercent = 0.025;
            laciProduction.ProteinDegradationPercent = 0.5;
            laciProduction.TrDelay = 0;
            

            // cits gene
            GeneExpression citsProduction = new GeneExpression();
            citsProduction.GenePromoter = Promoter2;
            citsProduction.TranscriptionRate = 10;
            citsProduction.TranslationRate = 1;
            citsProduction.mRNADegradationPercent= 0.025;
            citsProduction.ProteinDegradationPercent = 0.5;
            citsProduction.TrDelay = 0;            
     

            // GFP gene
            GeneExpression gfpProduction = new GeneExpression();
            gfpProduction.GenePromoter = Promoter2;
            gfpProduction.TranscriptionRate = 10;
            gfpProduction.TranslationRate = 1;
            gfpProduction.mRNADegradationPercent = 0.025;
            gfpProduction.ProteinDegradationPercent = 0.5;
            gfpProduction.TrDelay = 0;


            // External signals.
            bool IPTG = false;
            bool Heat = false;

            //================== SIMULATION ==================//
            for (int current_time = 0; current_time < Globals.SIMULATION_TIME; current_time++)
            {                              
                if (current_time == 0)
                {
                    IPTG = true;
                }

                /*if (current_time == 1)  // v tem primeru ne bo delovalo, ker IPTG prehitro odstranimo!
                {
                    IPTG = false;
                }*/

                if (current_time == 30)
                {
                    IPTG = false;
                }

                if (current_time == 220)
                {
                    Heat = true;
                }

                if (current_time == 340)    // če umaknemo kaj dosti prej, ne bo delovalo povsem ok (manj stabilno)...                
                {
                    Heat = false;
                }
                
                
                // LacI represses Promoter2 (Ptrc2).
                if (laci_proteins.Count >= Promoter2.RepressorBindSitesList[0].MaxCapacity) {
                    Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = Promoter2.RepressorBindSitesList[0].MaxCapacity;        // Bind MaxCapacity molecules to binding site when enough repressor is present.
                } else {
                    Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = laci_proteins.Count;        // Otherwise bind whatever amount of repressor is there.
                }

                // cIts represses Promoter1 (P1).
                if (cits_proteins.Count >= Promoter1.RepressorBindSitesList[0].MaxCapacity) {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = Promoter1.RepressorBindSitesList[0].MaxCapacity;        // Bind MaxCapacity molecules to binding site when enough repressor is present.
                } else {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = cits_proteins.Count;        // Otherwise bind whatever amount of repressor is there.
                }

                // IPTG prevents LacI from binding to Promoter2.
                if (IPTG)
                {
                    Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = 0;
                }
   

                // Heat prevents cIts from binding to Promoter1.
                if (Heat)
                {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = 0;
                }
                

                // mRNA production (transcription) & protein production (translation).
                laciProduction.Transcribe(ref laci_mRNAs, current_time);
                laciProduction.DegradeMRNA(ref laci_mRNAs);  

                laciProduction.Translate(ref laci_proteins, ref laci_mRNAs, current_time);
                laciProduction.DegradeProtein(ref laci_proteins);

                citsProduction.Transcribe(ref cits_mRNAs, current_time);
                citsProduction.DegradeMRNA(ref cits_mRNAs);

                citsProduction.Translate(ref cits_proteins, ref cits_mRNAs, current_time);
                citsProduction.DegradeProtein(ref cits_proteins);

                gfpProduction.Transcribe(ref gfp_mRNAs, current_time);
                gfpProduction.DegradeMRNA(ref gfp_mRNAs);

                gfpProduction.Translate(ref gfp_proteins, ref gfp_mRNAs, current_time);
                gfpProduction.DegradeProtein(ref gfp_proteins);

                //========== Capture data/stats. ==========//
                //Globals.NUM_MRNA = mRNAs.Count;
                //Globals.NUM_PROTEIN = proteins.Count;

                //if (Globals.NUM_PROTEIN > Globals.MAX_NUM_PROTEIN) { Globals.MAX_NUM_PROTEIN = Globals.NUM_PROTEIN; }
                //if (Globals.NUM_PROTEIN < Globals.MIN_NUM_PROTEIN) { Globals.MIN_NUM_PROTEIN = Globals.NUM_PROTEIN; }
                //if (Globals.NUM_MRNA > Globals.MAX_NUM_MRNA) { Globals.MAX_NUM_MRNA = Globals.NUM_MRNA; }
                //if (Globals.NUM_MRNA < Globals.MIN_NUM_MRNA) { Globals.MIN_NUM_MRNA = Globals.NUM_MRNA; }
                


                // Plotting.
                int x = current_time;
                int y_laci_mrna = laci_mRNAs.Count;
                int y_laci_protein = laci_proteins.Count;

                int y_cits_mrna = cits_mRNAs.Count;
                int y_cits_protein = cits_proteins.Count;

                int y_gfp_mrna = gfp_mRNAs.Count;
                int y_gfp_protein = gfp_proteins.Count;

                chart2.Series[0].Points.AddXY(x, y_laci_mrna);
                chart2.Series[1].Points.AddXY(x, y_laci_protein);

                chart2.Series[2].Points.AddXY(x, y_cits_mrna);
                chart2.Series[3].Points.AddXY(x, y_cits_protein);

                chart2.Series[4].Points.AddXY(x, y_gfp_mrna);
                chart2.Series[5].Points.AddXY(x, y_gfp_protein);

                //int yMRNA = Globals.NUM_MRNA;
                //int yP = Globals.NUM_PROTEIN;

                //chart2.Series[0].Points.AddXY(x, yMRNA);
                //chart2.Series[1].Points.AddXY(x, yP);

                // Data display etc.
                //textBox1.Text = Globals.MAX_NUM_MRNA.ToString();
                //textBox2.Text = Globals.MIN_NUM_MRNA.ToString();
                //textBox3.Text = Globals.MIN_NUM_PROTEIN.ToString();
                //textBox4.Text = Globals.MAX_NUM_PROTEIN.ToString();

                // Display simulation progress.
                progressBar1.Value = (int)Math.Round(100.0d * (double)(current_time + 1.0d) / (double)Globals.SIMULATION_TIME);   
            }
            
        }


        //========== NEGATIVE FEEDBACK LOOP OSCILLATOR ==========//
        private void button3_Click(object sender, EventArgs e)
        {
            // Plot settings
            chart2.ChartAreas[0].AxisY.LabelStyle.Interval = 10;

            for (int i = 0; i < chart2.Series.Count; i++)
            {
                chart2.Series[i].Points.Clear();
                chart2.Series[i].LegendText = "-";
            }


            chart2.Series[0].LegendText = "mRNA";
            chart2.Series[0].Color = Color.FromArgb(200, 225, 0, 0);
            chart2.Series[0].BorderWidth = 1;
            chart2.Series[0].Points.AddXY(0, 0);

            chart2.Series[1].LegendText = "Protein";
            chart2.Series[1].Color = Color.FromArgb(190, 255, 210, 100);
            chart2.Series[1].BorderWidth = 2;
            chart2.Series[1].Points.AddXY(0, 0);
        


            // Molecules lists
            List<Protein> proteins = new List<Protein>();         
            List<MRNA> mRNAs = new List<MRNA>();
           

            // Gene promoter            
            List<RepressorBindingSite> repr_bind_sites = new List<RepressorBindingSite>();

            RepressorBindingSite rbs1 = new RepressorBindingSite();
            rbs1.MaxCapacity = 30;
            repr_bind_sites.Add(rbs1);

          
            Promoter Promoter1 = new Promoter();
            Promoter1.Enabled = true;
            Promoter1.MaxTranscriptionRate = 40;
            Promoter1.Type = PromoterType.Constitutive;         
            Promoter1.RepressorBindSitesList = repr_bind_sites;
            Promoter1.Strength = 1;            

            // laci gene
            GeneExpression Production = new GeneExpression();
            Production.GenePromoter = Promoter1;
            Production.TranscriptionRate = 20;
            Production.TranslationRate = 2;
            Production.mRNADegradationPercent = 0.05;
            Production.ProteinDegradationPercent = 0.5;
            //Production.TrDelay = 0;   // no oscillations
            Production.TrDelay = 15;    // oscillations appear



            //================== SIMULATION ==================//
            for (int current_time = 0; current_time < Globals.SIMULATION_TIME; current_time++)
            {
                /*if (current_time == 100)
                {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = 20;
                }*/


                // Auto-repression of Promoter 1.
                if (proteins.Count >= Promoter1.RepressorBindSitesList[0].MaxCapacity)
                {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = Promoter1.RepressorBindSitesList[0].MaxCapacity;        // Bind MaxCapacity molecules to binding site when enough repressor is present.
                }
                else
                {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins.Count;        // Otherwise bind whatever amount of repressor is there.
                }                

                // mRNA production (transcription) & protein production (translation).
                Production.Transcribe(ref mRNAs, current_time);
                Production.DegradeMRNA(ref mRNAs);

                Production.Translate(ref proteins, ref mRNAs, current_time);                
                Production.DegradeProtein(ref proteins);

                //========== Capture data/stats and plotting. ==========//              

                // Plotting.
                int x = current_time;
                int y_laci_mrna = mRNAs.Count;
                int y_laci_protein = proteins.Count;

             
                chart2.Series[0].Points.AddXY(x, y_laci_mrna);
                chart2.Series[1].Points.AddXY(x, y_laci_protein);
         
                // Display simulation progress.                
                progressBar1.Value = (int)Math.Round(100.0d * (double)(current_time + 1.0d) / (double)Globals.SIMULATION_TIME);
            }
        }


        //========== AKTIVATORJI, REPRESORJI TEST ==========//
        private void button4_Click(object sender, EventArgs e)
        {
            // Plot settings
            chart2.ChartAreas[0].AxisY.LabelStyle.Interval = 10;

            for (int i = 0; i < chart2.Series.Count; i++)
            {
                chart2.Series[i].Points.Clear();
                chart2.Series[i].LegendText = "-";
            }

            chart2.Series[0].LegendText = "mRNA";
            chart2.Series[0].Color = Color.FromArgb(200, 225, 0, 0);
            chart2.Series[0].BorderWidth = 1;
            chart2.Series[0].Points.AddXY(0, 0);

            chart2.Series[1].LegendText = "Protein";
            chart2.Series[1].Color = Color.FromArgb(190, 255, 210, 100);
            chart2.Series[1].BorderWidth = 2;
            chart2.Series[1].Points.AddXY(0, 0);


            chart2.Series[2].LegendText = "Reporter";
            chart2.Series[2].Color = Color.FromArgb(220, 0, 225, 0);
            chart2.Series[2].BorderWidth = 1;
            chart2.Series[2].Points.AddXY(0, 0);


            // Molecules lists
            List<Protein> proteins = new List<Protein>();
            List<MRNA> mRNAs = new List<MRNA>();

            List<Protein> reporter_proteins = new List<Protein>();
            List<MRNA> reporter_mRNAs = new List<MRNA>();


            // Gene promoter            
            List<RepressorBindingSite> repr_bind_sites = new List<RepressorBindingSite>();
            RepressorBindingSite rbs1 = new RepressorBindingSite();
            RepressorBindingSite rbs2 = new RepressorBindingSite();
            
            repr_bind_sites.Add(rbs1);
            repr_bind_sites.Add(rbs2);

            List<ActivatorBindingSite> act_bind_sites = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs1 = new ActivatorBindingSite();
            act_bind_sites.Add(abs1);


            Promoter Promoter1 = new Promoter();
            Promoter1.Enabled = true;
            //Promoter1.Type = PromoterType.Constitutive;//
            Promoter1.Type = PromoterType.Activated;//  nujna prisotnost aktivatorja, da sprožimo transkripcijo
            Promoter1.RepressorBindSitesList = repr_bind_sites;
            Promoter1.ActivatorBindSitesList = act_bind_sites;
            Promoter1.Strength = 1;

            // laci gene
            GeneExpression Production = new GeneExpression();
            Production.GenePromoter = Promoter1;
            Production.TranscriptionRate = 10;
            Production.TranslationRate = 1;
            Production.mRNADegradationPercent = 0.015;
            Production.ProteinDegradationPercent = 0.5;
            Production.TrDelay = 0;

            // Reporter gene
            GeneExpression RProduction = new GeneExpression();
            RProduction.GenePromoter = Promoter1;
            RProduction.TranscriptionRate = 5;
            RProduction.TranslationRate = 1;
            RProduction.mRNADegradationPercent = 0.015;
            RProduction.ProteinDegradationPercent = 0.5;
            RProduction.TrDelay = 0;


            int represor1 = 0;      // (Amount of) repressor for repr. binding site 1.
            //int represor2 = 0;      // For repr. binding site 2.
            int activator1 = 0;     // For act. binding site 1.

            //================== SIMULATION ==================//
            for (int current_time = 0; current_time < Globals.SIMULATION_TIME; current_time++)
            {
                //--- SCENARIJ 1 - VEZAVA REPRESORJA, KONST. PROMOTOR ---//                
                /*if (current_time == 100)
                {
                    represor1 = 1; // malo represorja -> transkripcija upade le malo (ne zaduši se povsem)                    
                }

                if (current_time == 200)
                {
                    represor1 = 100; // veliko represorja -> transkripcija povsem upade
                }

                if (current_time == 300)
                {
                    activator1 = 5; // dodamo aktivator - brez ucinka, kjer je od t=100 naprej prisoten represor
                }


                // Repression - represor1 binds to repr. binding site [0]
                if (represor1 >= Promoter1.RepressorBindSitesList[0].MaxCapacity) {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = Promoter1.RepressorBindSitesList[0].MaxCapacity;
                } else {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = represor1;
                }

                // Vezava aktivatorja - ker smo prej vezali represor (ob t=100), ne bo vezava aktivatorja nič pomagala!
                if (activator1 >= Promoter1.ActivatorBindSitesList[0].MaxCapacity) {
                    Promoter1.ActivatorBindSitesList[0].AmountOfBoundActivator = Promoter1.ActivatorBindSitesList[0].MaxCapacity;
                } else {
                    Promoter1.ActivatorBindSitesList[0].AmountOfBoundActivator = activator1;
                }*/

                //--- SCENARIJ 2 - VEZAVA AKTIVATORJA, AKT. PROMOTER (nujen aktivator, da teče transkripcija) ---//
                
                if (current_time == 100)
                {
                    activator1 = 5;     // 5 enot aktivatorja1
                }

                if (current_time == 200)
                {
                    activator1 = 10;    // povečamo koncentracijo aktivatorja
                }

                if (current_time == 300)
                {
                    represor1 = 100;     // dodamo represor - povsem zatre transkricpijo
                }

                // Vezava aktivatorja sproži transkripcijo.
                if (activator1 >= Promoter1.ActivatorBindSitesList[0].MaxCapacity) {
                    Promoter1.ActivatorBindSitesList[0].AmountOfBoundActivator = Promoter1.ActivatorBindSitesList[0].MaxCapacity;
                } else {
                    Promoter1.ActivatorBindSitesList[0].AmountOfBoundActivator = activator1;
                }

                // Vezava represorja ne glede na vezan aktivator zatre transkripcijo.
                if (represor1 >= Promoter1.RepressorBindSitesList[0].MaxCapacity) {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = Promoter1.RepressorBindSitesList[0].MaxCapacity;
                } else {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = represor1;
                }
                



                // mRNA production (transcription) & protein production (translation).
                Production.Transcribe(ref mRNAs, current_time);
                Production.DegradeMRNA(ref mRNAs);

                Production.Translate(ref proteins, ref mRNAs, current_time);
                Production.DegradeProtein(ref proteins);

                RProduction.Transcribe(ref reporter_mRNAs, current_time);
                RProduction.DegradeMRNA(ref reporter_mRNAs);

                RProduction.Translate(ref reporter_proteins, ref reporter_mRNAs, current_time);
                RProduction.DegradeProtein(ref reporter_proteins);
                            
  

                //========== Capture data/stats and plotting. ==========//              

                // Plotting.
                int x = current_time;
                int y_laci_mrna = mRNAs.Count;
                int y_laci_protein = proteins.Count;


                chart2.Series[0].Points.AddXY(x, y_laci_mrna);
                chart2.Series[1].Points.AddXY(x, y_laci_protein);
                chart2.Series[2].Points.AddXY(x, reporter_proteins.Count);

                // Display simulation progress.
                progressBar1.Value = (int)Math.Round(100.0d * (double)(current_time + 1.0d) / (double)Globals.SIMULATION_TIME);
            }
        }


        //========== REPRESILATOR (3 geni) - slow ==========//
        // Uradni model: http://goo.gl/8xSZU
        private void button5_Click(object sender, EventArgs e)
        {
            // Plot settings
            Globals.SIMULATION_TIME = 10000;

            chart2.ChartAreas[0].AxisY.LabelStyle.Interval = 10000;
            chart2.ChartAreas[0].AxisY.MinorTickMark.Interval = 10000;
            chart2.ChartAreas[0].AxisY.MajorTickMark.Interval = 10000;
            chart2.ChartAreas[0].AxisX.LabelStyle.Interval = 1000;
            chart2.ChartAreas[0].AxisX.MinorTickMark.Interval = 1000;
            chart2.ChartAreas[0].AxisX.MajorTickMark.Interval = 1000;
            chart2.ChartAreas[0].AxisX.MajorGrid.Interval = 5000;
            chart2.ChartAreas[0].AxisX.MinorGrid.Interval = 5000;

            for (int i = 0; i < chart2.Series.Count; i++)
            {
                chart2.Series[i].Points.Clear();
                chart2.Series[i].LegendText = "-";
            }

            chart2.Series[0].LegendText = "mRNA 1";
            chart2.Series[0].Color = Color.FromArgb(200, 225, 0, 0);
            chart2.Series[0].BorderWidth = 1;
            chart2.Series[0].Points.AddXY(0, 0);

            chart2.Series[1].LegendText = "Protein 1";
            chart2.Series[1].Color = Color.FromArgb(120, 255, 0, 0);
            chart2.Series[1].BorderWidth = 1;
            chart2.Series[1].Points.AddXY(0, 0);

            chart2.Series[2].LegendText = "mRNA 2";
            chart2.Series[2].Color = Color.FromArgb(200, 0, 0, 225);
            chart2.Series[2].BorderWidth = 1;
            chart2.Series[2].Points.AddXY(0, 0);

            chart2.Series[3].LegendText = "Protein 2";
            chart2.Series[3].Color = Color.FromArgb(170, 0, 0, 255);
            chart2.Series[3].BorderWidth = 1;
            chart2.Series[3].Points.AddXY(0, 0);

            chart2.Series[4].LegendText = "mRNA 3";
            chart2.Series[4].Color = Color.FromArgb(140, 0, 225, 0);
            chart2.Series[4].BorderWidth = 1;
            chart2.Series[4].Points.AddXY(0, 0);

            chart2.Series[5].LegendText = "Protein 3";
            chart2.Series[5].Color = Color.FromArgb(190, 0, 255, 0);
            chart2.Series[5].BorderWidth = 1;
            chart2.Series[5].Points.AddXY(0, 0);            


            // Molecules lists
            List<Protein> proteins1 = new List<Protein>();
            List<Protein> proteins2 = new List<Protein>();
            List<Protein> proteins3 = new List<Protein>();

            List<MRNA> mRNAs1 = new List<MRNA>();
            List<MRNA> mRNAs2 = new List<MRNA>();
            List<MRNA> mRNAs3 = new List<MRNA>();



            // Promoter1
            List<RepressorBindingSite> rbs_list1 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs1 = new RepressorBindingSite();
            rbs1.MaxCapacity = 1000;
            rbs_list1.Add(rbs1);

            Promoter Promoter1 = new Promoter();
            Promoter1.Enabled = true;
            Promoter1.Type = PromoterType.Constitutive;
            Promoter1.Strength = 1;
            Promoter1.RepressorBindSitesList = rbs_list1;            

            
            // Promoter2
            List<RepressorBindingSite> rbs_list2 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs2 = new RepressorBindingSite();
            rbs2.MaxCapacity = 1000;
            rbs_list2.Add(rbs2);

            Promoter Promoter2 = new Promoter();
            Promoter2.Enabled = true;
            Promoter2.Type = PromoterType.Constitutive;
            Promoter2.Strength = 1;
            Promoter2.RepressorBindSitesList = rbs_list2;


            // Promoter3
            List<RepressorBindingSite> rbs_list3 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs3 = new RepressorBindingSite();
            rbs3.MaxCapacity = 1000;
            rbs_list3.Add(rbs3);

            Promoter Promoter3 = new Promoter();
            Promoter3.Enabled = true;
            Promoter3.Type = PromoterType.Constitutive;
            Promoter3.Strength = 1;
            Promoter3.RepressorBindSitesList = rbs_list3;
                        


            // Gene1
            GeneExpression PProduction1 = new GeneExpression();
            PProduction1.GenePromoter = Promoter1;
                PProduction1.TranscriptionRate = 35;
                PProduction1.TranslationRate = 1;
                PProduction1.Ka = 25;
                PProduction1.Kr = 25;

            PProduction1.mRNADegradationPercent = 0.02;
            PProduction1.ProteinDegradationPercent = 0.01;
            //PProduction1.TrDelay = 15;    // ZAMIK MED TRANSKRIPCIJO IN TRANSLACIJO NI NUJEN (lahko ga daš na 0 in bo še vedno osciliralo)!
            //PProduction1.TrDelay = 8;       // večji kot je hočemo delay, počasneje se mora degradirati protein, če hočemo še vedno dobiti oscilacije (npr. ProteinDegrPercent = 0.17, da dobimo oscilacije pri zamiku)

            
            // Gene2
            GeneExpression PProduction2 = new GeneExpression();
            PProduction2.GenePromoter = Promoter2;
                PProduction2.TranscriptionRate = 35;
                PProduction2.TranslationRate = 1;
                PProduction2.Ka = 25;
                PProduction2.Kr = 25;

            PProduction2.mRNADegradationPercent = 0.02;
            PProduction2.ProteinDegradationPercent = 0.01;
            //PProduction2.TrDelay = 15;
            //PProduction2.TrDelay = 8;

            // Gene3
            GeneExpression PProduction3 = new GeneExpression();
            PProduction3.GenePromoter = Promoter3;
                PProduction3.TranscriptionRate = 35;
                PProduction3.TranslationRate = 1;
                PProduction3.Ka = 25;
                PProduction3.Kr = 25;

            PProduction3.mRNADegradationPercent = 0.02;
            PProduction3.ProteinDegradationPercent = 0.01;
            //PProduction3.TrDelay = 15;
            //PProduction3.TrDelay = 8;
            

            // Initial state
            for (int i = 0; i < 500; i++)
            {
                mRNAs1.Add(new MRNA());
            }

            //================== SIMULATION ==================//
            for (int current_time = 0; current_time < Globals.SIMULATION_TIME; current_time++)
            {
                // Protein from gene 1 (proteins1) represses Promoter2.
                /*if (proteins1.Count >= Promoter2.RepressorBindSitesList[0].MaxCapacity) {
                    Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = Promoter2.RepressorBindSitesList[0].MaxCapacity;
                } else {
                    Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins1.Count;
                }

                // Protein from gene 2 (proteins2) represses Promoter3.
                if (proteins2.Count >= Promoter3.RepressorBindSitesList[0].MaxCapacity) {
                    Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = Promoter3.RepressorBindSitesList[0].MaxCapacity;
                } else {
                    Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins2.Count;
                }

                // Protein from gene 3 (proteins3) represses Promoter1.
                if (proteins3.Count >= Promoter1.RepressorBindSitesList[0].MaxCapacity) {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = Promoter1.RepressorBindSitesList[0].MaxCapacity;
                } else {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins3.Count;
                }*/

                Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins3.Count;
                Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins1.Count;
                Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins2.Count;


                // mRNA production (transcription) & protein production (translation).
                PProduction1.Transcribe(ref mRNAs1, current_time);
                PProduction1.DegradeMRNA(ref mRNAs1);

                PProduction1.Translate(ref proteins1, ref mRNAs1, current_time);
                PProduction1.DegradeProtein(ref proteins1);

                PProduction2.Transcribe(ref mRNAs2, current_time);
                PProduction2.DegradeMRNA(ref mRNAs2);

                PProduction2.Translate(ref proteins2, ref mRNAs2, current_time);
                PProduction2.DegradeProtein(ref proteins2);

                PProduction3.Transcribe(ref mRNAs3, current_time);
                PProduction3.DegradeMRNA(ref mRNAs3);

                PProduction3.Translate(ref proteins3, ref mRNAs3, current_time);
                PProduction3.DegradeProtein(ref proteins3);



                //========== Capture data/stats and plotting. ==========//                

                // Plotting.
                int x = current_time;
                int ymrna1 = mRNAs1.Count;
                int yprotein1 = proteins1.Count;

                int ymrna2 = mRNAs2.Count;
                int yprotein2 = proteins2.Count;

                int ymrna3 = mRNAs3.Count;
                int yprotein3 = proteins3.Count;

                //chart2.Series[0].Points.AddXY(x, ymrna1);
                chart2.Series[1].Points.AddXY(x, yprotein1);

                //chart2.Series[2].Points.AddXY(x, ymrna2);
                chart2.Series[3].Points.AddXY(x, yprotein2);

                //chart2.Series[4].Points.AddXY(x, ymrna3);
                chart2.Series[5].Points.AddXY(x, yprotein3);
                
                // Display simulation progress.
                progressBar1.Value = (int)Math.Round(100.0d * (double)(current_time + 1.0d) / (double)Globals.SIMULATION_TIME);
            }            

            Globals.SIMULATION_TIME = 500;
        }



        //========== REPRESILATOR (3 geni) - fast ==========//
        private void button7_Click(object sender, EventArgs e)
        {
            // Plot settings
            Globals.SIMULATION_TIME = 5000;
            
            chart2.ChartAreas[0].AxisY.LabelStyle.Interval = 100;
            chart2.ChartAreas[0].AxisY.MinorTickMark.Interval = 100;
            chart2.ChartAreas[0].AxisY.MajorTickMark.Interval = 100;
            chart2.ChartAreas[0].AxisX.LabelStyle.Interval = 500;
            chart2.ChartAreas[0].AxisX.MinorTickMark.Interval = 500;
            chart2.ChartAreas[0].AxisX.MajorTickMark.Interval = 500;
            chart2.ChartAreas[0].AxisX.MajorGrid.Interval = 500;
            chart2.ChartAreas[0].AxisX.MinorGrid.Interval = 500;

            for (int i = 0; i < chart2.Series.Count; i++)
            {
                chart2.Series[i].Points.Clear();
                chart2.Series[i].LegendText = "-";
            }

            chart2.Series[0].LegendText = "mRNA 1";
            chart2.Series[0].Color = Color.FromArgb(200, 225, 0, 0);
            chart2.Series[0].BorderWidth = 1;
            chart2.Series[0].Points.AddXY(0, 0);

            chart2.Series[1].LegendText = "Protein 1";
            chart2.Series[1].Color = Color.FromArgb(120, 255, 0, 0);
            chart2.Series[1].BorderWidth = 1;
            chart2.Series[1].Points.AddXY(0, 0);

            chart2.Series[2].LegendText = "mRNA 2";
            chart2.Series[2].Color = Color.FromArgb(200, 0, 0, 225);
            chart2.Series[2].BorderWidth = 1;
            chart2.Series[2].Points.AddXY(0, 0);

            chart2.Series[3].LegendText = "Protein 2";
            chart2.Series[3].Color = Color.FromArgb(170, 0, 0, 255);
            chart2.Series[3].BorderWidth = 1;
            chart2.Series[3].Points.AddXY(0, 0);

            chart2.Series[4].LegendText = "mRNA 3";
            chart2.Series[4].Color = Color.FromArgb(140, 0, 225, 0);
            chart2.Series[4].BorderWidth = 1;
            chart2.Series[4].Points.AddXY(0, 0);

            chart2.Series[5].LegendText = "Protein 3";
            chart2.Series[5].Color = Color.FromArgb(190, 0, 255, 0);
            chart2.Series[5].BorderWidth = 1;
            chart2.Series[5].Points.AddXY(0, 0);


            // Molecules lists
            List<Protein> proteins1 = new List<Protein>();
            List<Protein> proteins2 = new List<Protein>();
            List<Protein> proteins3 = new List<Protein>();

            List<MRNA> mRNAs1 = new List<MRNA>();
            List<MRNA> mRNAs2 = new List<MRNA>();
            List<MRNA> mRNAs3 = new List<MRNA>();



            // Promoter1
            List<RepressorBindingSite> rbs_list1 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs1 = new RepressorBindingSite();
            rbs1.MaxCapacity = 40;
            rbs_list1.Add(rbs1);

            Promoter Promoter1 = new Promoter();
            Promoter1.Enabled = true;
            Promoter1.Type = PromoterType.Constitutive;
            Promoter1.Strength = 1;
            Promoter1.RepressorBindSitesList = rbs_list1;


            // Promoter2
            List<RepressorBindingSite> rbs_list2 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs2 = new RepressorBindingSite();
            rbs2.MaxCapacity = 40;
            rbs_list2.Add(rbs2);

            Promoter Promoter2 = new Promoter();
            Promoter2.Enabled = true;
            Promoter2.Type = PromoterType.Constitutive;
            Promoter2.Strength = 1;
            Promoter2.RepressorBindSitesList = rbs_list2;


            // Promoter3
            List<RepressorBindingSite> rbs_list3 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs3 = new RepressorBindingSite();
            rbs3.MaxCapacity = 40;
            rbs_list3.Add(rbs3);

            Promoter Promoter3 = new Promoter();
            Promoter3.Enabled = true;
            Promoter3.Type = PromoterType.Constitutive;
            Promoter3.Strength = 1;
            Promoter3.RepressorBindSitesList = rbs_list3;



            // Gene1
            GeneExpression PProduction1 = new GeneExpression();
            PProduction1.GenePromoter = Promoter1;
            PProduction1.TranscriptionRate = 2;
            PProduction1.TranslationRate = 1;
            PProduction1.Ka = 1;
            PProduction1.Kr = 1;

            PProduction1.mRNADegradationPercent = 0.15;
            PProduction1.ProteinDegradationPercent = 0.01;
            //PProduction1.TrDelay = 15;    // ZAMIK MED TRANSKRIPCIJO IN TRANSLACIJO NI NUJEN (lahko ga daš na 0 in bo še vedno osciliralo)!
            //PProduction1.TrDelay = 8;       // večji kot je hočemo delay, počasneje se mora degradirati protein, če hočemo še vedno dobiti oscilacije (npr. ProteinDegrPercent = 0.17, da dobimo oscilacije pri zamiku)


            // Gene2
            GeneExpression PProduction2 = new GeneExpression();
            PProduction2.GenePromoter = Promoter2;
            PProduction2.TranscriptionRate = 2;
            PProduction2.TranslationRate = 1;
            PProduction2.Ka = 1;
            PProduction2.Kr = 1;

            PProduction2.mRNADegradationPercent = 0.15;
            PProduction2.ProteinDegradationPercent = 0.01;
            //PProduction2.TrDelay = 15;
            //PProduction2.TrDelay = 8;

            // Gene3
            GeneExpression PProduction3 = new GeneExpression();
            PProduction3.GenePromoter = Promoter3;
            PProduction3.TranscriptionRate = 2;
            PProduction3.TranslationRate = 1;
            PProduction3.Ka = 1;
            PProduction3.Kr = 1;

            PProduction3.mRNADegradationPercent = 0.15;
            PProduction3.ProteinDegradationPercent = 0.01;
            //PProduction3.TrDelay = 15;
            //PProduction3.TrDelay = 8;


            // Initial state
            for (int i = 0; i < 20; i++)
            {
                mRNAs1.Add(new MRNA());
            }

            //================== SIMULATION ==================//
            for (int current_time = 0; current_time < Globals.SIMULATION_TIME; current_time++)
            {
                // Protein from gene 1 (proteins1) represses Promoter2.
                if (proteins1.Count >= Promoter2.RepressorBindSitesList[0].MaxCapacity) {
                    Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = Promoter2.RepressorBindSitesList[0].MaxCapacity;
                } else {
                    Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins1.Count;
                }

                // Protein from gene 2 (proteins2) represses Promoter3.
                if (proteins2.Count >= Promoter3.RepressorBindSitesList[0].MaxCapacity) {
                    Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = Promoter3.RepressorBindSitesList[0].MaxCapacity;
                } else {
                    Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins2.Count;
                }

                // Protein from gene 3 (proteins3) represses Promoter1.
                if (proteins3.Count >= Promoter1.RepressorBindSitesList[0].MaxCapacity) {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = Promoter1.RepressorBindSitesList[0].MaxCapacity;
                } else {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins3.Count;
                }

                //Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins3.Count;
                //Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins1.Count;
                //Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = proteins2.Count;


                // mRNA production (transcription) & protein production (translation).
                PProduction1.Transcribe(ref mRNAs1, current_time);
                PProduction1.DegradeMRNA(ref mRNAs1);

                PProduction1.Translate(ref proteins1, ref mRNAs1, current_time);
                PProduction1.DegradeProtein(ref proteins1);

                PProduction2.Transcribe(ref mRNAs2, current_time);
                PProduction2.DegradeMRNA(ref mRNAs2);

                PProduction2.Translate(ref proteins2, ref mRNAs2, current_time);
                PProduction2.DegradeProtein(ref proteins2);

                PProduction3.Transcribe(ref mRNAs3, current_time);
                PProduction3.DegradeMRNA(ref mRNAs3);

                PProduction3.Translate(ref proteins3, ref mRNAs3, current_time);
                PProduction3.DegradeProtein(ref proteins3);



                //========== Capture data/stats and plotting. ==========//                

                // Plotting.
                int x = current_time;
                int ymrna1 = mRNAs1.Count;
                int yprotein1 = proteins1.Count;

                int ymrna2 = mRNAs2.Count;
                int yprotein2 = proteins2.Count;

                int ymrna3 = mRNAs3.Count;
                int yprotein3 = proteins3.Count;

                //chart2.Series[0].Points.AddXY(x, ymrna1);
                chart2.Series[1].Points.AddXY(x, yprotein1);

                //chart2.Series[2].Points.AddXY(x, ymrna2);
                chart2.Series[3].Points.AddXY(x, yprotein2);

                //chart2.Series[4].Points.AddXY(x, ymrna3);
                chart2.Series[5].Points.AddXY(x, yprotein3);

                // Display simulation progress.
                progressBar1.Value = (int)Math.Round(100.0d * (double)(current_time + 1.0d) / (double)Globals.SIMULATION_TIME);
            }

            Globals.SIMULATION_TIME = 500;
        }   



        //========== TRISTABILNO STIKALO, 2 INPUTA, VER. 2 ==========//     
        // url: sigem12.pbworks.com/f/1335731563/tristabilno_2_inputa_ver2.png
        private void button6_Click(object sender, EventArgs e)
        {
            Globals.SIMULATION_TIME = 1500;
            button6.Enabled = false;


            #region Plot settings
            // Plot settings            
            chart2.ChartAreas[0].AxisY.LabelStyle.Interval = 100;

            for (int i = 0; i < chart2.Series.Count; i++)
            {
                chart2.Series[i].Points.Clear();
                chart2.Series[i].LegendText = "-";
            }

            chart2.Series[0].LegendText = "TAL1rep mRNA";
            chart2.Series[0].Color = Color.FromArgb(90, 120, 0, 0);
            chart2.Series[0].BorderWidth = 1;
            chart2.Series[0].Points.AddXY(0, 0);

            chart2.Series[1].LegendText = "TAL1rep protein";
            chart2.Series[1].Color = Color.FromArgb(180, 120, 120, 120);
            chart2.Series[1].BorderWidth = 1;
            chart2.Series[1].Points.AddXY(0, 0);            

            chart2.Series[2].LegendText = "TAL2rep mRNA";
            chart2.Series[2].Color = Color.FromArgb(90, 0, 100, 0);
            chart2.Series[2].BorderWidth = 1;
            chart2.Series[2].Points.AddXY(0, 0);

            chart2.Series[3].LegendText = "TAL2rep protein";
            chart2.Series[3].Color = Color.FromArgb(180, 0, 100, 0);
            chart2.Series[3].BorderWidth = 1;
            chart2.Series[3].Points.AddXY(0, 0);

            chart2.Series[4].LegendText = "TAL3rep mRNA";
            chart2.Series[4].Color = Color.FromArgb(90, 0, 0, 180);
            chart2.Series[4].BorderWidth = 1;
            chart2.Series[4].Points.AddXY(0, 0);            

            chart2.Series[5].LegendText = "TAL3rep protein";
            chart2.Series[5].Color = Color.FromArgb(180, 0, 0, 180);
            chart2.Series[5].BorderWidth = 1;
            chart2.Series[5].Points.AddXY(0, 0);

            chart2.Series[6].LegendText = "TAL4akt mRNA";
            chart2.Series[6].Color = Color.FromArgb(90, 180, 120, 0);
            chart2.Series[6].BorderWidth = 1;
            chart2.Series[6].Points.AddXY(0, 0);

            chart2.Series[7].LegendText = "TAL4akt protein";
            chart2.Series[7].Color = Color.FromArgb(180, 180, 120, 0);
            chart2.Series[7].BorderWidth = 1;
            chart2.Series[7].Points.AddXY(0, 0);

            chart2.Series[8].LegendText = "TAL5akt mRNA";
            chart2.Series[8].Color = Color.FromArgb(90, 180, 180, 30);
            chart2.Series[8].BorderWidth = 1;
            chart2.Series[8].Points.AddXY(0, 0);

            chart2.Series[9].LegendText = "TAL5akt protein";
            chart2.Series[9].Color = Color.FromArgb(180, 180, 180, 30);
            chart2.Series[9].BorderWidth = 1;
            chart2.Series[9].Points.AddXY(0, 0);

            chart2.Series[10].LegendText = "Reporter1 mRNA";
            chart2.Series[10].Color = Color.FromArgb(120, 255, 0, 0);
            chart2.Series[10].BorderWidth = 1;
            chart2.Series[10].Points.AddXY(0, 0);

            chart2.Series[11].LegendText = "Reporter1 protein";
            chart2.Series[11].Color = Color.FromArgb(205, 255, 0, 0);
            chart2.Series[11].BorderWidth = 2;
            chart2.Series[11].Points.AddXY(0, 0);

            chart2.Series[12].LegendText = "Reporter2 mRNA";
            chart2.Series[12].Color = Color.FromArgb(120, 0, 255, 0);
            chart2.Series[12].BorderWidth = 1;
            chart2.Series[12].Points.AddXY(0, 0);

            chart2.Series[13].LegendText = "Reporter2 protein";
            chart2.Series[13].Color = Color.FromArgb(205, 0, 255, 0);
            chart2.Series[13].BorderWidth = 2;
            chart2.Series[13].Points.AddXY(0, 0);

            chart2.Series[14].LegendText = "Reporter3 mRNA";
            chart2.Series[14].Color = Color.FromArgb(120, 0, 0, 255);
            chart2.Series[14].BorderWidth = 1;
            chart2.Series[14].Points.AddXY(0, 0);

            chart2.Series[15].LegendText = "Reporter3 protein";
            chart2.Series[15].Color = Color.FromArgb(205, 0, 0, 255);
            chart2.Series[15].BorderWidth = 2;
            chart2.Series[15].Points.AddXY(0, 0);
            #endregion
            

            // Molecules lists
            List<Protein> TAL1rep = new List<Protein>();
            List<Protein> TAL2rep = new List<Protein>();
            List<Protein> TAL3rep = new List<Protein>();
            List<Protein> TAL4akt = new List<Protein>();
            List<Protein> TAL5akt = new List<Protein>();
            List<Protein> reporter1_proteins = new List<Protein>();
            List<Protein> reporter2_proteins = new List<Protein>();
            List<Protein> reporter3_proteins = new List<Protein>();

            List<MRNA> TAL1mRNA = new List<MRNA>();
            List<MRNA> TAL2mRNA = new List<MRNA>();
            List<MRNA> TAL3mRNA = new List<MRNA>();
            List<MRNA> TAL4mRNA = new List<MRNA>();
            List<MRNA> TAL5mRNA = new List<MRNA>();
            List<MRNA> reporter1_mrna = new List<MRNA>();
            List<MRNA> reporter2_mrna = new List<MRNA>();
            List<MRNA> reporter3_mrna = new List<MRNA>();


            #region Promotorji, geni ...
            //---------- PROMOTORJI ----------//

            // Promoter1 (konstrukt 1 z reporterjem 1)
            List<RepressorBindingSite> rbs_list1 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs1_TAL2 = new RepressorBindingSite();
            RepressorBindingSite rbs1_TAL3 = new RepressorBindingSite();
            rbs_list1.Add(rbs1_TAL2);
            rbs_list1.Add(rbs1_TAL3);

            Promoter Promoter1 = new Promoter();
            Promoter1.Enabled = true;
            Promoter1.Type = PromoterType.Constitutive;
            Promoter1.Strength = 1;
            Promoter1.RepressorBindSitesList = rbs_list1;



            // Promoter2 (konstrukt 2 z reporterjem 2)
            List<RepressorBindingSite> rbs_list2 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs2_TAL1 = new RepressorBindingSite();
            RepressorBindingSite rbs2_TAL3 = new RepressorBindingSite();
            rbs_list2.Add(rbs2_TAL1);
            rbs_list2.Add(rbs2_TAL3);

            Promoter Promoter2 = new Promoter();
            Promoter2.Enabled = true;
            Promoter2.Type = PromoterType.Constitutive;
            Promoter2.Strength = 1;
            Promoter2.RepressorBindSitesList = rbs_list2;            


            // Promoter3 (konstrukt 3 z reporterjem 3)
            List<RepressorBindingSite> rbs_list3 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs3_TAL1 = new RepressorBindingSite();
            RepressorBindingSite rbs3_TAL2 = new RepressorBindingSite();
            rbs_list3.Add(rbs3_TAL1);
            rbs_list3.Add(rbs3_TAL2);

            Promoter Promoter3 = new Promoter();
            Promoter3.Enabled = true;
            Promoter3.Type = PromoterType.Constitutive;
            Promoter3.Strength = 1;
            Promoter3.RepressorBindSitesList = rbs_list3;



            // IndPromoter1 (prvi inducibilni promotor s TAL4akt)            
            List<ActivatorBindingSite> abs_list1 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs1_inducer = new ActivatorBindingSite();
            abs_list1.Add(abs1_inducer);

            Promoter IndPromoter1 = new Promoter();
            IndPromoter1.Enabled = true;
            IndPromoter1.Type = PromoterType.Activated;
            IndPromoter1.Strength = 1;
            IndPromoter1.ActivatorBindSitesList = abs_list1;



            // IndPromoter2 (drugi inducibilni promotor s TAL5akt)            
            List<ActivatorBindingSite> abs_list2 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs2_inducer = new ActivatorBindingSite();            
            abs_list2.Add(abs2_inducer);

            Promoter IndPromoter2 = new Promoter();
            IndPromoter2.Enabled = true;
            IndPromoter2.Type = PromoterType.Activated;
            IndPromoter2.Strength = 1;
            IndPromoter2.ActivatorBindSitesList = abs_list2;



            // MinPromoter1 (prvi min promotor s TAL1rep)            
            List<ActivatorBindingSite> abs_list3 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs4_1 = new ActivatorBindingSite();            
            abs_list3.Add(abs4_1);

            Promoter MinPromoter1 = new Promoter();
            MinPromoter1.Enabled = true;
            MinPromoter1.Type = PromoterType.Activated;
            MinPromoter1.Strength = 1;
            MinPromoter1.ActivatorBindSitesList = abs_list3;


            // MinPromoter2 (drugi min promotor s TAL2rep)            
            List<ActivatorBindingSite> abs_list4 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs5_1 = new ActivatorBindingSite();            
            abs_list4.Add(abs5_1);
            
            Promoter MinPromoter2 = new Promoter();
            MinPromoter2.Enabled = true;
            MinPromoter2.Type = PromoterType.Activated;
            MinPromoter2.Strength = 1;
            MinPromoter2.ActivatorBindSitesList = abs_list4;



            // MinPromoter3 (tretji min promotor s TAL3rep)            
            List<ActivatorBindingSite> abs_list5 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs4_11 = new ActivatorBindingSite();            
            ActivatorBindingSite abs5_11 = new ActivatorBindingSite();            

            abs_list5.Add(abs4_11);
            abs_list5.Add(abs5_11);

            Promoter MinPromoter3 = new Promoter();
            MinPromoter3.Enabled = true;
            MinPromoter3.Type = PromoterType.Activated;
            MinPromoter3.Strength = 1;
            MinPromoter3.ActivatorBindSitesList = abs_list5;



            //---------- GENI ----------//
         
            // TAL1rep gene pod konst. promotorjem
            GeneExpression TAL1rep_Konst_Production = new GeneExpression();
            TAL1rep_Konst_Production.GenePromoter = Promoter1;
            TAL1rep_Konst_Production.TranscriptionRate = 10;
            TAL1rep_Konst_Production.TranslationRate = 1;
            TAL1rep_Konst_Production.mRNADegradationPercent = 0.25;
            TAL1rep_Konst_Production.ProteinDegradationPercent = 0.05;
            TAL1rep_Konst_Production.TrDelay = 0;


            // TAL2rep gene pod konst. promotorjem
            GeneExpression TAL2rep_Konst_Production = new GeneExpression();
            TAL2rep_Konst_Production.GenePromoter = Promoter2;
            TAL2rep_Konst_Production.TranscriptionRate = 10;
            TAL2rep_Konst_Production.TranslationRate = 1;
            TAL2rep_Konst_Production.mRNADegradationPercent = 0.25;
            TAL2rep_Konst_Production.ProteinDegradationPercent = 0.05;
            TAL2rep_Konst_Production.TrDelay = 0;


            // TAL3rep gene pod konst. promotorjem
            GeneExpression TAL3rep_Konst_Production = new GeneExpression();
            TAL3rep_Konst_Production.GenePromoter = Promoter3;
            TAL3rep_Konst_Production.TranscriptionRate = 10;
            TAL3rep_Konst_Production.TranslationRate = 1;
            TAL3rep_Konst_Production.mRNADegradationPercent = 0.25;
            TAL3rep_Konst_Production.ProteinDegradationPercent = 0.05;
            TAL3rep_Konst_Production.TrDelay = 0;


            // TAL1rep gene pod min. promotorjem
            GeneExpression TAL1rep_Min_Production = new GeneExpression();
            TAL1rep_Min_Production.GenePromoter = MinPromoter1;
            TAL1rep_Min_Production.TranscriptionRate = 10;
            TAL1rep_Min_Production.TranslationRate = 1;
            TAL1rep_Min_Production.mRNADegradationPercent = 0.25;
            TAL1rep_Min_Production.ProteinDegradationPercent = 0.05;
            TAL1rep_Min_Production.TrDelay = 0;

            // TAL2rep gene pod min. promotorjem
            GeneExpression TAL2rep_Min_Production = new GeneExpression();
            TAL2rep_Min_Production.GenePromoter = MinPromoter2;
            TAL2rep_Min_Production.TranscriptionRate = 10;
            TAL2rep_Min_Production.TranslationRate = 1;
            TAL2rep_Min_Production.mRNADegradationPercent = 0.25;
            TAL2rep_Min_Production.ProteinDegradationPercent = 0.05;
            TAL2rep_Min_Production.TrDelay = 0;


            // TAL3rep gene pod min. promotorjem
            GeneExpression TAL3rep_Min_Production = new GeneExpression();
            TAL3rep_Min_Production.GenePromoter = MinPromoter3;
            TAL3rep_Min_Production.TranscriptionRate = 10;
            TAL3rep_Min_Production.TranslationRate = 1;
            TAL3rep_Min_Production.mRNADegradationPercent = 0.25;
            TAL3rep_Min_Production.ProteinDegradationPercent = 0.05;
            TAL3rep_Min_Production.TrDelay = 0;


            // TAL4akt gene pod min. promotorjem
            GeneExpression TAL4akt_Min_Production = new GeneExpression();
            TAL4akt_Min_Production.GenePromoter = IndPromoter1;
            TAL4akt_Min_Production.TranscriptionRate = 10;
            TAL4akt_Min_Production.TranslationRate = 1;
            TAL4akt_Min_Production.mRNADegradationPercent = 0.25;
            TAL4akt_Min_Production.ProteinDegradationPercent = 0.05;
            TAL4akt_Min_Production.TrDelay = 0;


            // TAL5akt gene pod min. promotorjem
            GeneExpression TAL5akt_Min_Production = new GeneExpression();
            TAL5akt_Min_Production.GenePromoter = IndPromoter2;
            TAL5akt_Min_Production.TranscriptionRate = 10;
            TAL5akt_Min_Production.TranslationRate = 1;
            TAL5akt_Min_Production.mRNADegradationPercent = 0.25;
            TAL5akt_Min_Production.ProteinDegradationPercent = 0.05;
            TAL5akt_Min_Production.TrDelay = 0;


            // Reporter1 gene
            GeneExpression Reporter1_Production = new GeneExpression();
            Reporter1_Production.GenePromoter = Promoter1;
            Reporter1_Production.TranscriptionRate = 10;
            Reporter1_Production.TranslationRate = 1;
            Reporter1_Production.mRNADegradationPercent = 0.25;
            Reporter1_Production.ProteinDegradationPercent = 0.05;
            Reporter1_Production.TrDelay = 0;


            // Reporter2 gene
            GeneExpression Reporter2_Production = new GeneExpression();
            Reporter2_Production.GenePromoter = Promoter2;
            Reporter2_Production.TranscriptionRate = 10;
            Reporter2_Production.TranslationRate = 1;
            Reporter2_Production.mRNADegradationPercent = 0.25;
            Reporter2_Production.ProteinDegradationPercent = 0.05;
            Reporter2_Production.TrDelay = 0;


            // Reporter3 gene
            GeneExpression Reporter3_Production = new GeneExpression();
            Reporter3_Production.GenePromoter = Promoter3;
            Reporter3_Production.TranscriptionRate = 10;
            Reporter3_Production.TranslationRate = 1;
            Reporter3_Production.mRNADegradationPercent = 0.25;
            Reporter3_Production.ProteinDegradationPercent = 0.05;
            Reporter3_Production.TrDelay = 0;

            #endregion


            // Max transcription rates
            /*Promoter1.MaxTranscriptionRate = 30;
            Promoter2.MaxTranscriptionRate = 30;
            Promoter3.MaxTranscriptionRate = 30;
            MinPromoter1.MaxTranscriptionRate = 30;
            MinPromoter2.MaxTranscriptionRate = 30;
            MinPromoter3.MaxTranscriptionRate = 30;
            IndPromoter1.MaxTranscriptionRate = 10;
            IndPromoter2.MaxTranscriptionRate = 10;*/            



            // Zunanji signali - inputi
            int inducer1 = 0;
            int inducer2 = 0;


            #region Simulacija
            //================== SIMULATION ==================//
            for (int current_time = 0; current_time < Globals.SIMULATION_TIME; current_time++)
            {
                
                // induciramo stanje 1 (reporter1) 20 časovnih enot
                if (current_time == 100)
                {
                    inducer1 = 1;          
                }
                if (current_time == 110)    // stabilno stanje 1 (reporter 1 = visok) se po umiku inducerja kot pričakovano ohrani ...
                {
                    inducer1 = 0;
                }
                
                // induciramo stanje 2 (reporter2) 20 časovnih enot
                if (current_time == 500)
                {
                    inducer2 = 1;
                }
                if (current_time == 510)
                {
                    inducer2 = 0;
                }
                
                // induciramo stanje 3 (reporter3) 20 časovnih enot
                if (current_time == 1000)
                {
                    inducer1 = 1;
                    inducer2 = 1;
                }
                if (current_time == 1010)   // če držimo samo 10 enot časa, ne bo dovolj za vzpostavitev ...
                {
                    inducer1 = 0;
                    inducer2 = 0;
                }


                // nazaj stanje 1 (za test)
                if (current_time == 1200)
                {
                    inducer1 = 1;
                }
                if (current_time == 1210)
                {
                    inducer1 = 0;
                }

             
                // asimetričen poskus induciranja stanja 3
                /*if (current_time == 1000)
                {
                    inducer1 = 1;                 
                }
                if (current_time == 1008)
                {                    
                    inducer2 = 1;
                }
                if (current_time == 1030)
                {
                    inducer1 = 0;
                }
                if (current_time == 1032)       // razmik med časom umika obeh inducerjev ne sme biti prevelik...
                {
                    inducer2 = 0;
                }*/


                // Test 1 - direktno dodajanje TALakttivatorjev, ne prek inducerjev
                // Ta način deluje oz. vodi v 3 stabilna stanja (direktno "dodajanje" aktivatorja, ki ga sicer produciramo prek dodajanja inducerja)
                /*if (current_time == 100)
                {
                    // PAZI - reporter se ne bo tvoril takoj (ob t=100), ko dodamo aktivator (preko inducerja), saj se trije (konst.) geni nekaj časa
                    // "tepejo" premoč oz. medsebojno represirajo - tisti, ki zmaga (v primeru dodanega TAL4akt je to TAL1rep oz. gen 1, ki po nekem času zatre gena 2 in 3),
                    // potem ni več represiran in začne tvoriti reporter 
                    TAL4akt.Add(new Protein());
                    TAL4akt.Add(new Protein());
                    TAL4akt.Add(new Protein());
 
                    //TAL5akt.Add(new Protein());
                    //TAL5akt.Add(new Protein());
                    //TAL5akt.Add(new Protein());       
                }*/


                /*
                // Test 2 - proženje preko inducerjev - deluje, vendar samo, če inducer po nekem času odstranimo, 
                // da se neha represija dveh konst. genov hkrati (in da lahko en konst. gen - manj represiran -prevlada in tako začne izražati tudi reporter!
                if (current_time == 100)
                {
                    inducer1 = 1;
                }
                // PO NEKEM ČASU MORAMO INDUCER ODSTRANITI! Sicer se medsebojna represija (ker en inducer povzroči ekspresijo 2 TALrep pod dvema min. promotorjema) dveh konstruktov (opisano
                // zgoraj pod testom) nadaljuje in noben gen ne prevlada - ker stalno tvorimo (min.) TALrepresorje, ki preprečita, da bi en konst. gen postal sčasoma nerepresiran in tako
                // začel izražati reporter!
                if (current_time == 102)
                {
                    inducer1 = 0;
                }
                */

                //

                //int boundTAL4akt = MinPromoter1.ActivatorBindSitesList[0].AmountOfBoundActivator + MinPromoter3.ActivatorBindSitesList[0].AmountOfBoundActivator;
                //int boundTAL5akt = MinPromoter2.ActivatorBindSitesList[0].AmountOfBoundActivator + MinPromoter3.ActivatorBindSitesList[1].AmountOfBoundActivator;
                 
                // 


          
                // Interakcije (represija, aktivacija)                 
                Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = (int)Math.Round((double)TAL2rep.Count/2.0d);   // TAL2rep ima v celem omrežju 2 možni vezavni mesti (na 2 različnih konstruktih) - na vsakega ga vežemo polovico
                Promoter1.RepressorBindSitesList[1].AmountOfBoundRepressor = (int)Math.Round((double)TAL3rep.Count/2.0d);

                Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = (int)Math.Round((double)TAL1rep.Count/2.0d);
                Promoter2.RepressorBindSitesList[1].AmountOfBoundRepressor = (int)Math.Round((double)TAL3rep.Count/2.0d);
                
                Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = (int)Math.Round((double)TAL1rep.Count/2.0d);
                Promoter3.RepressorBindSitesList[1].AmountOfBoundRepressor = (int)Math.Round((double)TAL2rep.Count/2.0d);
                
                MinPromoter1.ActivatorBindSitesList[0].AmountOfBoundActivator = (int)Math.Round((double)TAL4akt.Count * 0.6d);  // TAL4akt ima v celem omrežju 5 tarč (možnih vezavnih mest) - na tem (MinPromoter1) konstruktru ima 3 od 5 vezavnih mest: 3/5 = 0.6
                MinPromoter2.ActivatorBindSitesList[0].AmountOfBoundActivator = (int)Math.Round((double)TAL5akt.Count * 0.6d);
                MinPromoter3.ActivatorBindSitesList[0].AmountOfBoundActivator = (int)Math.Round((double)TAL4akt.Count * 0.4d);
                MinPromoter3.ActivatorBindSitesList[1].AmountOfBoundActivator = (int)Math.Round((double)TAL5akt.Count * 0.4d);

                IndPromoter1.ActivatorBindSitesList[0].AmountOfBoundActivator = inducer1;
                IndPromoter2.ActivatorBindSitesList[0].AmountOfBoundActivator = inducer2;


                if (Globals.LIMIT_BINDING_SITE_CAPACITY)
                {
                    Promoter1.LimitAmountOfBoundTF();
                    Promoter2.LimitAmountOfBoundTF();
                    Promoter3.LimitAmountOfBoundTF();

                    MinPromoter1.LimitAmountOfBoundTF();
                    MinPromoter2.LimitAmountOfBoundTF();
                    MinPromoter3.LimitAmountOfBoundTF();

                    IndPromoter1.LimitAmountOfBoundTF();
                    IndPromoter2.LimitAmountOfBoundTF();
                }



                // mRNA production (transcription) & protein production (translation).
                TAL1rep_Konst_Production.Transcribe(ref TAL1mRNA, current_time);
                TAL1rep_Konst_Production.DegradeMRNA(ref TAL1mRNA);
                TAL1rep_Konst_Production.Translate(ref TAL1rep, ref TAL1mRNA, current_time);
                TAL1rep_Konst_Production.DegradeProtein(ref TAL1rep);

                TAL2rep_Konst_Production.Transcribe(ref TAL2mRNA, current_time);
                TAL2rep_Konst_Production.DegradeMRNA(ref TAL2mRNA);
                TAL2rep_Konst_Production.Translate(ref TAL2rep, ref TAL2mRNA, current_time);
                TAL2rep_Konst_Production.DegradeProtein(ref TAL2rep);

                TAL3rep_Konst_Production.Transcribe(ref TAL3mRNA, current_time);
                TAL3rep_Konst_Production.DegradeMRNA(ref TAL3mRNA);
                TAL3rep_Konst_Production.Translate(ref TAL3rep, ref TAL3mRNA, current_time);
                TAL3rep_Konst_Production.DegradeProtein(ref TAL3rep);

                TAL1rep_Min_Production.Transcribe(ref TAL1mRNA, current_time);
                TAL1rep_Min_Production.DegradeMRNA(ref TAL1mRNA);
                TAL1rep_Min_Production.Translate(ref TAL1rep, ref TAL1mRNA, current_time);
                TAL1rep_Min_Production.DegradeProtein(ref TAL1rep);

                TAL2rep_Min_Production.Transcribe(ref TAL2mRNA, current_time);
                TAL2rep_Min_Production.DegradeMRNA(ref TAL2mRNA);
                TAL2rep_Min_Production.Translate(ref TAL2rep, ref TAL2mRNA, current_time);
                TAL2rep_Min_Production.DegradeProtein(ref TAL2rep);

                TAL3rep_Min_Production.Transcribe(ref TAL3mRNA, current_time);
                TAL3rep_Min_Production.DegradeMRNA(ref TAL3mRNA);
                TAL3rep_Min_Production.Translate(ref TAL3rep, ref TAL3mRNA, current_time);
                TAL3rep_Min_Production.DegradeProtein(ref TAL3rep);

                Reporter1_Production.Transcribe(ref reporter1_mrna, current_time);
                Reporter1_Production.DegradeMRNA(ref reporter1_mrna);
                Reporter1_Production.Translate(ref reporter1_proteins, ref reporter1_mrna, current_time);
                Reporter1_Production.DegradeProtein(ref reporter1_proteins);

                Reporter2_Production.Transcribe(ref reporter2_mrna, current_time);
                Reporter2_Production.DegradeMRNA(ref reporter2_mrna);
                Reporter2_Production.Translate(ref reporter2_proteins, ref reporter2_mrna, current_time);
                Reporter2_Production.DegradeProtein(ref reporter2_proteins);

                Reporter3_Production.Transcribe(ref reporter3_mrna, current_time);
                Reporter3_Production.DegradeMRNA(ref reporter3_mrna);
                Reporter3_Production.Translate(ref reporter3_proteins, ref reporter3_mrna, current_time);
                Reporter3_Production.DegradeProtein(ref reporter3_proteins);

                TAL4akt_Min_Production.Transcribe(ref TAL4mRNA, current_time);
                TAL4akt_Min_Production.DegradeMRNA(ref TAL4mRNA);
                TAL4akt_Min_Production.Translate(ref TAL4akt, ref TAL4mRNA, current_time);
                TAL4akt_Min_Production.DegradeProtein(ref TAL4akt);

                TAL5akt_Min_Production.Transcribe(ref TAL5mRNA, current_time);
                TAL5akt_Min_Production.DegradeMRNA(ref TAL5mRNA);
                TAL5akt_Min_Production.Translate(ref TAL5akt, ref TAL5mRNA, current_time);
                TAL5akt_Min_Production.DegradeProtein(ref TAL5akt);



                //========== Capture data/stats and plotting. ==========//                


                // Plotting.
                int x = current_time;
                int ymrna_reporter1 = reporter1_mrna.Count;
                int yreporter1 = reporter1_proteins.Count;

                int ymrna_reporter2 = reporter2_mrna.Count;
                int yreporter2 = reporter2_proteins.Count;

                int ymrna_reporter3 = reporter3_mrna.Count;
                int yreporter3 = reporter3_proteins.Count;

                int yTAL1mRNA = TAL1mRNA.Count;
                int yTAL2mRNA = TAL2mRNA.Count;
                int yTAL3mRNA = TAL3mRNA.Count;
                int yTAL4mRNA = TAL4mRNA.Count;
                int yTAL5mRNA = TAL5mRNA.Count;

                int yTAL1rep = TAL1rep.Count;
                int yTAL2rep = TAL2rep.Count;
                int yTAL3rep = TAL3rep.Count;
                int yTAL4akt = TAL4akt.Count;
                int yTAL5akt = TAL5akt.Count;

                chart2.Series[0].Points.AddXY(x, yTAL1mRNA);
                chart2.Series[1].Points.AddXY(x, yTAL1rep);

                chart2.Series[2].Points.AddXY(x, yTAL2mRNA);
                chart2.Series[3].Points.AddXY(x, yTAL2rep);

                chart2.Series[4].Points.AddXY(x, yTAL3mRNA);
                chart2.Series[5].Points.AddXY(x, yTAL3rep);

                chart2.Series[6].Points.AddXY(x, yTAL4mRNA);
                chart2.Series[7].Points.AddXY(x, yTAL4akt);

                chart2.Series[8].Points.AddXY(x, yTAL5mRNA);
                chart2.Series[9].Points.AddXY(x, yTAL5akt);

                chart2.Series[10].Points.AddXY(x, ymrna_reporter1);
                chart2.Series[11].Points.AddXY(x, yreporter1);

                chart2.Series[12].Points.AddXY(x, ymrna_reporter2);
                chart2.Series[13].Points.AddXY(x, yreporter2);

                chart2.Series[14].Points.AddXY(x, ymrna_reporter3);
                chart2.Series[15].Points.AddXY(x, yreporter3);                

                // Display simulation progress.
                progressBar1.Value = (int)Math.Round(100.0d * (double)(current_time + 1.0d) / (double)Globals.SIMULATION_TIME);
            }           

            #endregion


            // Plot display settings (what to display).
            if (checkBoxReporter.Checked) {
                chart2.Series[11].Enabled = true;   chart2.Series[13].Enabled = true;   chart2.Series[15].Enabled = true;
            } else {
                chart2.Series[11].Enabled = false;  chart2.Series[13].Enabled = false;  chart2.Series[15].Enabled = false;
            }

            if (checkBoxProtein.Checked) {
                chart2.Series[1].Enabled = true; chart2.Series[3].Enabled = true; chart2.Series[5].Enabled = true;
                chart2.Series[7].Enabled = true; chart2.Series[9].Enabled = true;
            } else {
                chart2.Series[1].Enabled = false; chart2.Series[3].Enabled = false; chart2.Series[5].Enabled = false;
                chart2.Series[7].Enabled = false; chart2.Series[9].Enabled = false;
            }

            if (checkBoxMRNA.Checked) {
                chart2.Series[0].Enabled = true; chart2.Series[2].Enabled = true; chart2.Series[4].Enabled = true;
                chart2.Series[6].Enabled = true; chart2.Series[8].Enabled = true; chart2.Series[10].Enabled = true;
                chart2.Series[12].Enabled = true; chart2.Series[14].Enabled = true;
            } else {
                chart2.Series[0].Enabled = false; chart2.Series[2].Enabled = false; chart2.Series[4].Enabled = false;
                chart2.Series[6].Enabled = false; chart2.Series[8].Enabled = false; chart2.Series[10].Enabled = false;
                chart2.Series[12].Enabled = false; chart2.Series[14].Enabled = false;
            }


            /// Write chart data to txt - so you can later use it in MATLAB etc. ///
            if (checkBox1.Checked)
            {
                using (StreamWriter writer = new StreamWriter(textBox6.Text))
                {                    
                    // Writer reporter1 (Series[11]) data
                    writer.Write("reporter1_x = [");
                    for (int i = 0; i < chart2.Series[11].Points.Count; i++)
                    {
                        writer.Write(chart2.Series[11].Points[i].XValue + " ");
                    }
                    writer.Write("];");

                    writer.WriteLine();
                    writer.WriteLine();

                    writer.Write("reporter1_y = [");
                    for (int i = 0; i < chart2.Series[11].Points.Count; i++)
                    {
                        writer.Write(chart2.Series[11].Points[i].YValues[0] + " ");
                    }
                    writer.Write("];");
                }
                
            }


            Globals.LAST_RUN_SIMULATION_NAME = "3stable_verzija2";
            Globals.SIMULATION_TIME = 500;
            button6.Enabled = true;
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {
                Globals.TRANSCRIPTION_MODEL = 2;
            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                Globals.TRANSCRIPTION_MODEL = 1;
            }
        }

        private void checkBoxReporter_CheckedChanged(object sender, EventArgs e)
        {
            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija2"))
            {
                if (checkBoxReporter.Checked)
                {
                    chart2.Series[11].Enabled = true; chart2.Series[13].Enabled = true; chart2.Series[15].Enabled = true;
                }
                else
                {
                    chart2.Series[11].Enabled = false; chart2.Series[13].Enabled = false; chart2.Series[15].Enabled = false;
                }
            }

            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija1"))
            {
                if (checkBoxReporter.Checked)
                {
                    chart2.Series[11].Enabled = true; chart2.Series[13].Enabled = true; chart2.Series[15].Enabled = true;
                }
                else
                {
                    chart2.Series[11].Enabled = false; chart2.Series[13].Enabled = false; chart2.Series[15].Enabled = false;
                }
            }

            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija3"))
            {
                if (checkBoxReporter.Checked)
                {
                    chart2.Series[11].Enabled = true; chart2.Series[13].Enabled = true; chart2.Series[15].Enabled = true;
                }
                else
                {
                    chart2.Series[11].Enabled = false; chart2.Series[13].Enabled = false; chart2.Series[15].Enabled = false;
                }
            }


            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija5"))
            {
                if (checkBoxReporter.Checked)
                {
                    chart2.Series[11].Enabled = true; chart2.Series[13].Enabled = true; chart2.Series[15].Enabled = true;
                }
                else
                {
                    chart2.Series[11].Enabled = false; chart2.Series[13].Enabled = false; chart2.Series[15].Enabled = false;
                }
            }
        }

        private void checkBoxProtein_CheckedChanged(object sender, EventArgs e)
        {
            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija2"))
            {
                if (checkBoxProtein.Checked)
                {
                    chart2.Series[1].Enabled = true; chart2.Series[3].Enabled = true; chart2.Series[5].Enabled = true;
                    chart2.Series[7].Enabled = true; chart2.Series[9].Enabled = true;
                }
                else
                {
                    chart2.Series[1].Enabled = false; chart2.Series[3].Enabled = false; chart2.Series[5].Enabled = false;
                    chart2.Series[7].Enabled = false; chart2.Series[9].Enabled = false;
                }
            }

            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija1"))
            {
                if (checkBoxProtein.Checked)
                {
                    chart2.Series[1].Enabled = true; chart2.Series[3].Enabled = true; chart2.Series[5].Enabled = true;
                }
                else
                {
                    chart2.Series[1].Enabled = false; chart2.Series[3].Enabled = false; chart2.Series[5].Enabled = false;
                }
            }

            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija3"))
            {
                if (checkBoxProtein.Checked)
                {
                    chart2.Series[1].Enabled = true; chart2.Series[3].Enabled = true; chart2.Series[5].Enabled = true;
                }
                else
                {
                    chart2.Series[1].Enabled = false; chart2.Series[3].Enabled = false; chart2.Series[5].Enabled = false;
                }
            }


            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija5"))
            {
                if (checkBoxProtein.Checked)
                {
                    chart2.Series[1].Enabled = true; chart2.Series[3].Enabled = true; chart2.Series[5].Enabled = true;
                }
                else
                {
                    chart2.Series[1].Enabled = false; chart2.Series[3].Enabled = false; chart2.Series[5].Enabled = false;
                }
            }

        }

        private void checkBoxMRNA_CheckedChanged(object sender, EventArgs e)
        {
            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija2"))
            {
                if (checkBoxMRNA.Checked)
                {
                    chart2.Series[0].Enabled = true; chart2.Series[2].Enabled = true; chart2.Series[4].Enabled = true;
                    chart2.Series[6].Enabled = true; chart2.Series[8].Enabled = true; chart2.Series[10].Enabled = true;
                    chart2.Series[12].Enabled = true; chart2.Series[14].Enabled = true;
                }
                else
                {
                    chart2.Series[0].Enabled = false; chart2.Series[2].Enabled = false; chart2.Series[4].Enabled = false;
                    chart2.Series[6].Enabled = false; chart2.Series[8].Enabled = false; chart2.Series[10].Enabled = false;
                    chart2.Series[12].Enabled = false; chart2.Series[14].Enabled = false;
                }
            }

            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija1"))
            {
                if (checkBoxMRNA.Checked)
                {
                    chart2.Series[0].Enabled = true; chart2.Series[2].Enabled = true; chart2.Series[4].Enabled = true;
                    chart2.Series[10].Enabled = true; chart2.Series[12].Enabled = true; chart2.Series[14].Enabled = true;
                }
                else
                {
                    chart2.Series[0].Enabled = false; chart2.Series[2].Enabled = false; chart2.Series[4].Enabled = false;
                    chart2.Series[10].Enabled = false; chart2.Series[12].Enabled = false; chart2.Series[14].Enabled = false;

                }
            }


            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija3"))
            {
                if (checkBoxMRNA.Checked)
                {
                    chart2.Series[0].Enabled = true; chart2.Series[2].Enabled = true; chart2.Series[4].Enabled = true;
                    chart2.Series[10].Enabled = true; chart2.Series[12].Enabled = true; chart2.Series[14].Enabled = true;
                }
                else
                {
                    chart2.Series[0].Enabled = false; chart2.Series[2].Enabled = false; chart2.Series[4].Enabled = false;
                    chart2.Series[10].Enabled = false; chart2.Series[12].Enabled = false; chart2.Series[14].Enabled = false;
                }
            }

            if (Globals.LAST_RUN_SIMULATION_NAME.Equals("3stable_verzija5"))
            {
                if (checkBoxMRNA.Checked)
                {
                    chart2.Series[0].Enabled = true; chart2.Series[2].Enabled = true; chart2.Series[4].Enabled = true;
                    chart2.Series[10].Enabled = true; chart2.Series[12].Enabled = true; chart2.Series[14].Enabled = true;
                }
                else
                {
                    chart2.Series[0].Enabled = false; chart2.Series[2].Enabled = false; chart2.Series[4].Enabled = false;
                    chart2.Series[10].Enabled = false; chart2.Series[12].Enabled = false; chart2.Series[14].Enabled = false;
                }
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            chart2.ChartAreas[0].RecalculateAxesScale();
        }


        //========== TRISTABILNO STIKALO, 2 INPUTA, VER. 1 ==========//     
        // url: sigem12.pbworks.com/f/1335731562/tristabilno_2_inputa_ver1.png
        private void button9_Click(object sender, EventArgs e)
        {
            Globals.SIMULATION_TIME = 1500;
            button9.Enabled = false;


            #region Plot settings
            // Plot settings            
            chart2.ChartAreas[0].AxisY.LabelStyle.Interval = 100;

            for (int i = 0; i < chart2.Series.Count; i++)
            {
                chart2.Series[i].Points.Clear();
                chart2.Series[i].LegendText = "-";
            }

            chart2.Series[0].LegendText = "TAL1rep mRNA";
            chart2.Series[0].Color = Color.FromArgb(90, 120, 0, 0);
            chart2.Series[0].BorderWidth = 1;
            chart2.Series[0].Points.AddXY(0, 0);

            chart2.Series[1].LegendText = "TAL1rep protein";
            chart2.Series[1].Color = Color.FromArgb(180, 120, 120, 120);
            chart2.Series[1].BorderWidth = 1;
            chart2.Series[1].Points.AddXY(0, 0);

            chart2.Series[2].LegendText = "TAL2rep mRNA";
            chart2.Series[2].Color = Color.FromArgb(90, 0, 100, 0);
            chart2.Series[2].BorderWidth = 1;
            chart2.Series[2].Points.AddXY(0, 0);

            chart2.Series[3].LegendText = "TAL2rep protein";
            chart2.Series[3].Color = Color.FromArgb(180, 0, 100, 0);
            chart2.Series[3].BorderWidth = 1;
            chart2.Series[3].Points.AddXY(0, 0);

            chart2.Series[4].LegendText = "TAL3rep mRNA";
            chart2.Series[4].Color = Color.FromArgb(90, 0, 0, 180);
            chart2.Series[4].BorderWidth = 1;
            chart2.Series[4].Points.AddXY(0, 0);

            chart2.Series[5].LegendText = "TAL3rep protein";
            chart2.Series[5].Color = Color.FromArgb(180, 0, 0, 180);
            chart2.Series[5].BorderWidth = 1;
            chart2.Series[5].Points.AddXY(0, 0);

            chart2.Series[10].LegendText = "Reporter1 mRNA";
            chart2.Series[10].Color = Color.FromArgb(120, 255, 0, 0);
            chart2.Series[10].BorderWidth = 1;
            chart2.Series[10].Points.AddXY(0, 0);

            chart2.Series[11].LegendText = "Reporter1 protein";
            chart2.Series[11].Color = Color.FromArgb(205, 255, 0, 0);
            chart2.Series[11].BorderWidth = 2;
            chart2.Series[11].Points.AddXY(0, 0);

            chart2.Series[12].LegendText = "Reporter2 mRNA";
            chart2.Series[12].Color = Color.FromArgb(120, 0, 255, 0);
            chart2.Series[12].BorderWidth = 1;
            chart2.Series[12].Points.AddXY(0, 0);

            chart2.Series[13].LegendText = "Reporter2 protein";
            chart2.Series[13].Color = Color.FromArgb(205, 0, 255, 0);
            chart2.Series[13].BorderWidth = 2;
            chart2.Series[13].Points.AddXY(0, 0);

            chart2.Series[14].LegendText = "Reporter3 mRNA";
            chart2.Series[14].Color = Color.FromArgb(120, 0, 0, 255);
            chart2.Series[14].BorderWidth = 1;
            chart2.Series[14].Points.AddXY(0, 0);

            chart2.Series[15].LegendText = "Reporter3 protein";
            chart2.Series[15].Color = Color.FromArgb(205, 0, 0, 255);
            chart2.Series[15].BorderWidth = 2;
            chart2.Series[15].Points.AddXY(0, 0);
            #endregion


            // Molecules lists
            List<Protein> TAL1rep = new List<Protein>();
            List<Protein> TAL2rep = new List<Protein>();
            List<Protein> TAL3rep = new List<Protein>();            
            List<Protein> reporter1_proteins = new List<Protein>();
            List<Protein> reporter2_proteins = new List<Protein>();
            List<Protein> reporter3_proteins = new List<Protein>();

            List<MRNA> TAL1mRNA = new List<MRNA>();
            List<MRNA> TAL2mRNA = new List<MRNA>();
            List<MRNA> TAL3mRNA = new List<MRNA>();            
            List<MRNA> reporter1_mrna = new List<MRNA>();
            List<MRNA> reporter2_mrna = new List<MRNA>();
            List<MRNA> reporter3_mrna = new List<MRNA>();


            #region Promotorji, geni ...
            //---------- PROMOTORJI ----------//

            // Promoter1 (konstrukt 1 z reporterjem 1)
            List<RepressorBindingSite> rbs_list1 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs1_TAL2 = new RepressorBindingSite();
            RepressorBindingSite rbs1_TAL3 = new RepressorBindingSite();
            rbs_list1.Add(rbs1_TAL2);
            rbs_list1.Add(rbs1_TAL3);
            Promoter Promoter1 = new Promoter();
            Promoter1.Enabled = true;
            Promoter1.Type = PromoterType.Constitutive;
            Promoter1.Strength = 1;
            Promoter1.RepressorBindSitesList = rbs_list1;



            // Promoter2 (konstrukt 2 z reporterjem 2)
            List<RepressorBindingSite> rbs_list2 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs2_TAL1 = new RepressorBindingSite();
            RepressorBindingSite rbs2_TAL3 = new RepressorBindingSite();
            rbs_list2.Add(rbs2_TAL1);
            rbs_list2.Add(rbs2_TAL3);
            Promoter Promoter2 = new Promoter();
            Promoter2.Enabled = true;
            Promoter2.Type = PromoterType.Constitutive;
            Promoter2.Strength = 1;
            Promoter2.RepressorBindSitesList = rbs_list2;


            // Promoter3 (konstrukt 3 z reporterjem 3)
            List<RepressorBindingSite> rbs_list3 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs3_TAL1 = new RepressorBindingSite();
            RepressorBindingSite rbs3_TAL2 = new RepressorBindingSite();
            rbs_list3.Add(rbs3_TAL1);
            rbs_list3.Add(rbs3_TAL2);
            Promoter Promoter3 = new Promoter();
            Promoter3.Enabled = true;
            Promoter3.Type = PromoterType.Constitutive;
            Promoter3.Strength = 1;
            Promoter3.RepressorBindSitesList = rbs_list3;



            // MinPromoter1 (prvi min promotor s TAL1rep)            
            List<ActivatorBindingSite> abs_list3 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs4_1 = new ActivatorBindingSite();            
            abs_list3.Add(abs4_1);            
            Promoter MinPromoter1 = new Promoter();
            MinPromoter1.Enabled = true;
            MinPromoter1.Type = PromoterType.Activated;
            MinPromoter1.Strength = 1;
            MinPromoter1.ActivatorBindSitesList = abs_list3;


            // MinPromoter2 (drugi min promotor s TAL2rep)            
            List<ActivatorBindingSite> abs_list4 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs5_1 = new ActivatorBindingSite();
            abs_list4.Add(abs5_1);
            Promoter MinPromoter2 = new Promoter();
            MinPromoter2.Enabled = true;
            MinPromoter2.Type = PromoterType.Activated;
            MinPromoter2.Strength = 1;
            MinPromoter2.ActivatorBindSitesList = abs_list4;


            // MinPromoter3 (tretji min promotor s TAL3rep)            
            List<ActivatorBindingSite> abs_list5 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs4_11 = new ActivatorBindingSite();
            ActivatorBindingSite abs5_11 = new ActivatorBindingSite();
            abs_list5.Add(abs4_11);
            abs_list5.Add(abs5_11);
            Promoter MinPromoter3 = new Promoter();
            MinPromoter3.Enabled = true;
            MinPromoter3.Type = PromoterType.Activated;
            MinPromoter3.Strength = 1;
            MinPromoter3.ActivatorBindSitesList = abs_list5;



            //---------- GENI ----------//

            // TAL1rep gene pod konst. promotorjem
            GeneExpression TAL1rep_Konst_Production = new GeneExpression();
            TAL1rep_Konst_Production.GenePromoter = Promoter1;
            TAL1rep_Konst_Production.TranscriptionRate = 10;
            TAL1rep_Konst_Production.TranslationRate = 1;
            TAL1rep_Konst_Production.mRNADegradationPercent = 0.25;
            TAL1rep_Konst_Production.ProteinDegradationPercent = 0.05;
            TAL1rep_Konst_Production.TrDelay = 0;


            // TAL2rep gene pod konst. promotorjem
            GeneExpression TAL2rep_Konst_Production = new GeneExpression();
            TAL2rep_Konst_Production.GenePromoter = Promoter2;
            TAL2rep_Konst_Production.TranscriptionRate = 10;
            TAL2rep_Konst_Production.TranslationRate = 1;
            TAL2rep_Konst_Production.mRNADegradationPercent = 0.25;
            TAL2rep_Konst_Production.ProteinDegradationPercent = 0.05;
            TAL2rep_Konst_Production.TrDelay = 0;


            // TAL3rep gene pod konst. promotorjem
            GeneExpression TAL3rep_Konst_Production = new GeneExpression();
            TAL3rep_Konst_Production.GenePromoter = Promoter3;
            TAL3rep_Konst_Production.TranscriptionRate = 10;
            TAL3rep_Konst_Production.TranslationRate = 1;
            TAL3rep_Konst_Production.mRNADegradationPercent = 0.25;
            TAL3rep_Konst_Production.ProteinDegradationPercent = 0.05;
            TAL3rep_Konst_Production.TrDelay = 0;


            // TAL1rep gene pod min. promotorjem
            GeneExpression TAL1rep_Min_Production = new GeneExpression();
            TAL1rep_Min_Production.GenePromoter = MinPromoter1;
            TAL1rep_Min_Production.TranscriptionRate = 10;
            TAL1rep_Min_Production.TranslationRate = 1;
            TAL1rep_Min_Production.mRNADegradationPercent = 0.25;
            TAL1rep_Min_Production.ProteinDegradationPercent = 0.05;
            TAL1rep_Min_Production.TrDelay = 0;

            // TAL2rep gene pod min. promotorjem
            GeneExpression TAL2rep_Min_Production = new GeneExpression();
            TAL2rep_Min_Production.GenePromoter = MinPromoter2;
            TAL2rep_Min_Production.TranscriptionRate = 10;
            TAL2rep_Min_Production.TranslationRate = 1;
            TAL2rep_Min_Production.mRNADegradationPercent = 0.25;
            TAL2rep_Min_Production.ProteinDegradationPercent = 0.05;
            TAL2rep_Min_Production.TrDelay = 0;


            // TAL3rep gene pod min. promotorjem
            GeneExpression TAL3rep_Min_Production = new GeneExpression();
            TAL3rep_Min_Production.GenePromoter = MinPromoter3;
            TAL3rep_Min_Production.TranscriptionRate = 10;
            TAL3rep_Min_Production.TranslationRate = 1;
            TAL3rep_Min_Production.mRNADegradationPercent = 0.25;
            TAL3rep_Min_Production.ProteinDegradationPercent = 0.05;
            TAL3rep_Min_Production.TrDelay = 0;


            // Reporter1 gene
            GeneExpression Reporter1_Production = new GeneExpression();
            Reporter1_Production.GenePromoter = Promoter1;
            Reporter1_Production.TranscriptionRate = 10;
            Reporter1_Production.TranslationRate = 1;
            Reporter1_Production.mRNADegradationPercent = 0.25;
            Reporter1_Production.ProteinDegradationPercent = 0.05;
            Reporter1_Production.TrDelay = 0;


            // Reporter2 gene
            GeneExpression Reporter2_Production = new GeneExpression();
            Reporter2_Production.GenePromoter = Promoter2;
            Reporter2_Production.TranscriptionRate = 10;
            Reporter2_Production.TranslationRate = 1;
            Reporter2_Production.mRNADegradationPercent = 0.25;
            Reporter2_Production.ProteinDegradationPercent = 0.05;
            Reporter2_Production.TrDelay = 0;


            // Reporter3 gene
            GeneExpression Reporter3_Production = new GeneExpression();
            Reporter3_Production.GenePromoter = Promoter3;
            Reporter3_Production.TranscriptionRate = 10;
            Reporter3_Production.TranslationRate = 1;
            Reporter3_Production.mRNADegradationPercent = 0.25;
            Reporter3_Production.ProteinDegradationPercent = 0.05;
            Reporter3_Production.TrDelay = 0;

            #endregion



            // Zunanji signali - inputi
            int inducer1 = 0;
            int inducer2 = 0;


            #region Simulacija
            //================== SIMULATION ==================//
            for (int current_time = 0; current_time < Globals.SIMULATION_TIME; current_time++)
            {
                // stanje 1
                if (current_time == 100)
                {
                    inducer1 = 30;
                }
                if (current_time == 110)    
                {
                    inducer1 = 0;
                }

                // stanje 2
                if (current_time == 500)
                {
                    inducer2 = 30;
                }
                if (current_time == 510)
                {
                    inducer2 = 0;
                }

                // stanje 3
                if (current_time == 800)
                {
                    inducer1 = 30;
                    inducer2 = 30;
                }
                //if (current_time == 805)   // ne bo delalo - premalo časa smo držali inducer
                if (current_time == 810)
                {
                    inducer1 = 0;
                    inducer2 = 0;
                }


                // nazaj stanj1
                if (current_time == 1020)
                {
                    inducer1 = 30;                         
                }
                if (current_time == 1040)
                {
                    inducer1 = 0;
                }



                // Interakcije (represija, aktivacija)                 
                Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = (int)Math.Round((double)TAL2rep.Count / 2.0d);   // TAL2rep ima v celem omrežju 2 možni vezavni mesti (na 2 različnih konstruktih) - na vsakega ga vežemo polovico
                Promoter1.RepressorBindSitesList[1].AmountOfBoundRepressor = (int)Math.Round((double)TAL3rep.Count / 2.0d);

                Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = (int)Math.Round((double)TAL1rep.Count / 2.0d);
                Promoter2.RepressorBindSitesList[1].AmountOfBoundRepressor = (int)Math.Round((double)TAL3rep.Count / 2.0d);

                Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = (int)Math.Round((double)TAL1rep.Count / 2.0d);
                Promoter3.RepressorBindSitesList[1].AmountOfBoundRepressor = (int)Math.Round((double)TAL2rep.Count / 2.0d);

                MinPromoter1.ActivatorBindSitesList[0].AmountOfBoundActivator = (int)Math.Round((double)inducer1 * 0.6d);
                MinPromoter2.ActivatorBindSitesList[0].AmountOfBoundActivator = (int)Math.Round((double)inducer2 * 0.6d);

                MinPromoter3.ActivatorBindSitesList[0].AmountOfBoundActivator = (int)Math.Round((double)inducer1 * 0.4d);
                MinPromoter3.ActivatorBindSitesList[1].AmountOfBoundActivator = (int)Math.Round((double)inducer2 * 0.4d);

                if (Globals.LIMIT_BINDING_SITE_CAPACITY)
                {
                    Promoter1.LimitAmountOfBoundTF();
                    Promoter2.LimitAmountOfBoundTF();
                    Promoter3.LimitAmountOfBoundTF();

                    MinPromoter1.LimitAmountOfBoundTF();
                    MinPromoter2.LimitAmountOfBoundTF();
                    MinPromoter3.LimitAmountOfBoundTF();
                }


                // mRNA production (transcription) & protein production (translation).
                TAL1rep_Konst_Production.Transcribe(ref TAL1mRNA, current_time);
                TAL1rep_Konst_Production.DegradeMRNA(ref TAL1mRNA);
                TAL1rep_Konst_Production.Translate(ref TAL1rep, ref TAL1mRNA, current_time);
                TAL1rep_Konst_Production.DegradeProtein(ref TAL1rep);

                TAL2rep_Konst_Production.Transcribe(ref TAL2mRNA, current_time);
                TAL2rep_Konst_Production.DegradeMRNA(ref TAL2mRNA);
                TAL2rep_Konst_Production.Translate(ref TAL2rep, ref TAL2mRNA, current_time);
                TAL2rep_Konst_Production.DegradeProtein(ref TAL2rep);

                TAL3rep_Konst_Production.Transcribe(ref TAL3mRNA, current_time);
                TAL3rep_Konst_Production.DegradeMRNA(ref TAL3mRNA);
                TAL3rep_Konst_Production.Translate(ref TAL3rep, ref TAL3mRNA, current_time);
                TAL3rep_Konst_Production.DegradeProtein(ref TAL3rep);

                TAL1rep_Min_Production.Transcribe(ref TAL1mRNA, current_time);
                TAL1rep_Min_Production.DegradeMRNA(ref TAL1mRNA);
                TAL1rep_Min_Production.Translate(ref TAL1rep, ref TAL1mRNA, current_time);
                TAL1rep_Min_Production.DegradeProtein(ref TAL1rep);

                TAL2rep_Min_Production.Transcribe(ref TAL2mRNA, current_time);
                TAL2rep_Min_Production.DegradeMRNA(ref TAL2mRNA);
                TAL2rep_Min_Production.Translate(ref TAL2rep, ref TAL2mRNA, current_time);
                TAL2rep_Min_Production.DegradeProtein(ref TAL2rep);

                TAL3rep_Min_Production.Transcribe(ref TAL3mRNA, current_time);
                TAL3rep_Min_Production.DegradeMRNA(ref TAL3mRNA);
                TAL3rep_Min_Production.Translate(ref TAL3rep, ref TAL3mRNA, current_time);
                TAL3rep_Min_Production.DegradeProtein(ref TAL3rep);

                Reporter1_Production.Transcribe(ref reporter1_mrna, current_time);
                Reporter1_Production.DegradeMRNA(ref reporter1_mrna);
                Reporter1_Production.Translate(ref reporter1_proteins, ref reporter1_mrna, current_time);
                Reporter1_Production.DegradeProtein(ref reporter1_proteins);

                Reporter2_Production.Transcribe(ref reporter2_mrna, current_time);
                Reporter2_Production.DegradeMRNA(ref reporter2_mrna);
                Reporter2_Production.Translate(ref reporter2_proteins, ref reporter2_mrna, current_time);
                Reporter2_Production.DegradeProtein(ref reporter2_proteins);

                Reporter3_Production.Transcribe(ref reporter3_mrna, current_time);
                Reporter3_Production.DegradeMRNA(ref reporter3_mrna);
                Reporter3_Production.Translate(ref reporter3_proteins, ref reporter3_mrna, current_time);
                Reporter3_Production.DegradeProtein(ref reporter3_proteins);



                //========== Capture data/stats and plotting. ==========//                


                // Plotting.
                int x = current_time;
                int ymrna_reporter1 = reporter1_mrna.Count;
                int yreporter1 = reporter1_proteins.Count;
                int ymrna_reporter2 = reporter2_mrna.Count;
                int yreporter2 = reporter2_proteins.Count;
                int ymrna_reporter3 = reporter3_mrna.Count;
                int yreporter3 = reporter3_proteins.Count;
                int yTAL1mRNA = TAL1mRNA.Count;
                int yTAL2mRNA = TAL2mRNA.Count;
                int yTAL3mRNA = TAL3mRNA.Count;
                int yTAL1rep = TAL1rep.Count;
                int yTAL2rep = TAL2rep.Count;
                int yTAL3rep = TAL3rep.Count;


                chart2.Series[0].Points.AddXY(x, yTAL1mRNA);
                chart2.Series[1].Points.AddXY(x, yTAL1rep);

                chart2.Series[2].Points.AddXY(x, yTAL2mRNA);
                chart2.Series[3].Points.AddXY(x, yTAL2rep);

                chart2.Series[4].Points.AddXY(x, yTAL3mRNA);
                chart2.Series[5].Points.AddXY(x, yTAL3rep);

                chart2.Series[10].Points.AddXY(x, ymrna_reporter1);
                chart2.Series[11].Points.AddXY(x, yreporter1);

                chart2.Series[12].Points.AddXY(x, ymrna_reporter2);
                chart2.Series[13].Points.AddXY(x, yreporter2);

                chart2.Series[14].Points.AddXY(x, ymrna_reporter3);
                chart2.Series[15].Points.AddXY(x, yreporter3);

                // Display simulation progress.
                progressBar1.Value = (int)Math.Round(100.0d * (double)(current_time + 1.0d) / (double)Globals.SIMULATION_TIME);
            }

            #endregion


            // Plot display settings (what to display).
            if (checkBoxReporter.Checked)
            {
                chart2.Series[11].Enabled = true; chart2.Series[13].Enabled = true; chart2.Series[15].Enabled = true;
            }
            else
            {
                chart2.Series[11].Enabled = false; chart2.Series[13].Enabled = false; chart2.Series[15].Enabled = false;
            }

            if (checkBoxProtein.Checked)
            {
                chart2.Series[1].Enabled = true; chart2.Series[3].Enabled = true; chart2.Series[5].Enabled = true;
            }
            else
            {
                chart2.Series[1].Enabled = false; chart2.Series[3].Enabled = false; chart2.Series[5].Enabled = false;
            }

            if (checkBoxMRNA.Checked)
            {
                chart2.Series[0].Enabled = true; chart2.Series[2].Enabled = true; chart2.Series[4].Enabled = true;
                chart2.Series[10].Enabled = true; chart2.Series[12].Enabled = true; chart2.Series[14].Enabled = true;
            }
            else
            {
                chart2.Series[0].Enabled = false; chart2.Series[2].Enabled = false; chart2.Series[4].Enabled = false;
                chart2.Series[10].Enabled = false; chart2.Series[12].Enabled = false; chart2.Series[14].Enabled = false;
            }


            /// Write chart data to txt - so you can later use it in MATLAB etc. ///
            if (checkBox1.Checked)
            {
                using (StreamWriter writer = new StreamWriter(textBox6.Text))
                {
                    // Writer reporter1 (Series[11]) data
                    writer.Write("reporter1_x = [");
                    for (int i = 0; i < chart2.Series[11].Points.Count; i++)
                    {
                        writer.Write(chart2.Series[11].Points[i].XValue + " ");
                    }
                    writer.Write("];");

                    writer.WriteLine();
                    writer.WriteLine();

                    writer.Write("reporter1_y = [");
                    for (int i = 0; i < chart2.Series[11].Points.Count; i++)
                    {
                        writer.Write(chart2.Series[11].Points[i].YValues[0] + " ");
                    }
                    writer.Write("];");
                }

            }


            Globals.LAST_RUN_SIMULATION_NAME = "3stable_verzija1";
            Globals.SIMULATION_TIME = 500;
            button9.Enabled = true;
        }



        private void checkBoxKapacitetaOmejena_CheckedChanged(object sender, EventArgs e)
        {
            Globals.LIMIT_BINDING_SITE_CAPACITY = checkBoxKapacitetaOmejena.Checked;
        }



        //========== TRISTABILNO STIKALO, 2 INPUTA, VER. 3 ==========// 
        // url: sigem12.pbworks.com/f/1335731561/tristabilno_2_inputa_ver3.png
        private void button10_Click(object sender, EventArgs e)
        {
            Globals.SIMULATION_TIME = 1500;
            button10.Enabled = false;

            #region Plot settings
            // Plot settings            
            chart2.ChartAreas[0].AxisY.LabelStyle.Interval = 100;

            for (int i = 0; i < chart2.Series.Count; i++)
            {
                chart2.Series[i].Points.Clear();
                chart2.Series[i].LegendText = "-";
            }

            chart2.Series[0].LegendText = "TAL1rep mRNA";
            chart2.Series[0].Color = Color.FromArgb(90, 120, 0, 0);
            chart2.Series[0].BorderWidth = 1;
            chart2.Series[0].Points.AddXY(0, 0);

            chart2.Series[1].LegendText = "TAL1rep protein";
            chart2.Series[1].Color = Color.FromArgb(180, 120, 120, 120);
            chart2.Series[1].BorderWidth = 1;
            chart2.Series[1].Points.AddXY(0, 0);

            chart2.Series[2].LegendText = "TAL2rep mRNA";
            chart2.Series[2].Color = Color.FromArgb(90, 0, 100, 0);
            chart2.Series[2].BorderWidth = 1;
            chart2.Series[2].Points.AddXY(0, 0);

            chart2.Series[3].LegendText = "TAL2rep protein";
            chart2.Series[3].Color = Color.FromArgb(180, 0, 100, 0);
            chart2.Series[3].BorderWidth = 1;
            chart2.Series[3].Points.AddXY(0, 0);

            chart2.Series[4].LegendText = "TAL3rep mRNA";
            chart2.Series[4].Color = Color.FromArgb(90, 0, 0, 180);
            chart2.Series[4].BorderWidth = 1;
            chart2.Series[4].Points.AddXY(0, 0);

            chart2.Series[5].LegendText = "TAL3rep protein";
            chart2.Series[5].Color = Color.FromArgb(180, 0, 0, 180);
            chart2.Series[5].BorderWidth = 1;
            chart2.Series[5].Points.AddXY(0, 0);

            chart2.Series[10].LegendText = "Reporter1 mRNA";
            chart2.Series[10].Color = Color.FromArgb(120, 255, 0, 0);
            chart2.Series[10].BorderWidth = 1;
            chart2.Series[10].Points.AddXY(0, 0);

            chart2.Series[11].LegendText = "Reporter1 protein";
            chart2.Series[11].Color = Color.FromArgb(205, 255, 0, 0);
            chart2.Series[11].BorderWidth = 2;
            chart2.Series[11].Points.AddXY(0, 0);

            chart2.Series[12].LegendText = "Reporter2 mRNA";
            chart2.Series[12].Color = Color.FromArgb(120, 0, 255, 0);
            chart2.Series[12].BorderWidth = 1;
            chart2.Series[12].Points.AddXY(0, 0);

            chart2.Series[13].LegendText = "Reporter2 protein";
            chart2.Series[13].Color = Color.FromArgb(205, 0, 255, 0);
            chart2.Series[13].BorderWidth = 2;
            chart2.Series[13].Points.AddXY(0, 0);

            chart2.Series[14].LegendText = "Reporter3 mRNA";
            chart2.Series[14].Color = Color.FromArgb(120, 0, 0, 255);
            chart2.Series[14].BorderWidth = 1;
            chart2.Series[14].Points.AddXY(0, 0);

            chart2.Series[15].LegendText = "Reporter3 protein";
            chart2.Series[15].Color = Color.FromArgb(205, 0, 0, 255);
            chart2.Series[15].BorderWidth = 2;
            chart2.Series[15].Points.AddXY(0, 0);
            #endregion


            // Molecules lists
            List<Protein> TAL1rep = new List<Protein>();
            List<Protein> TAL2rep = new List<Protein>();
            List<Protein> TAL3rep = new List<Protein>();
            List<Protein> reporter1_proteins = new List<Protein>();
            List<Protein> reporter2_proteins = new List<Protein>();
            List<Protein> reporter3_proteins = new List<Protein>();

            List<MRNA> TAL1mRNA = new List<MRNA>();
            List<MRNA> TAL2mRNA = new List<MRNA>();
            List<MRNA> TAL3mRNA = new List<MRNA>();
            List<MRNA> reporter1_mrna = new List<MRNA>();
            List<MRNA> reporter2_mrna = new List<MRNA>();
            List<MRNA> reporter3_mrna = new List<MRNA>();


            #region Promotorji, geni ...
            //---------- PROMOTORJI ----------//

            // Promoter1 (konstrukt 1 z reporterjem 1)
            List<RepressorBindingSite> rbs_list1 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs1_TAL2 = new RepressorBindingSite();            
            rbs_list1.Add(rbs1_TAL2);            
            Promoter Promoter1 = new Promoter();
            Promoter1.Enabled = true;
            Promoter1.Type = PromoterType.Constitutive;
            Promoter1.Strength = 1;
            Promoter1.RepressorBindSitesList = rbs_list1;



            // Promoter2 (konstrukt 2 z reporterjem 2)
            List<RepressorBindingSite> rbs_list2 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs2_TAL3 = new RepressorBindingSite();            
            rbs_list2.Add(rbs2_TAL3);            
            Promoter Promoter2 = new Promoter();
            Promoter2.Enabled = true;
            Promoter2.Type = PromoterType.Constitutive;
            Promoter2.Strength = 1;
            Promoter2.RepressorBindSitesList = rbs_list2;


            // Promoter3 (konstrukt 3 z reporterjem 3)
            List<RepressorBindingSite> rbs_list3 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs3_TAL1 = new RepressorBindingSite();            
            rbs_list3.Add(rbs3_TAL1);            
            Promoter Promoter3 = new Promoter();
            Promoter3.Enabled = true;
            Promoter3.Type = PromoterType.Constitutive;
            Promoter3.Strength = 1;
            Promoter3.RepressorBindSitesList = rbs_list3;



            // MinPromoter1 (prvi min promotor s TAL1rep)            
            List<ActivatorBindingSite> abs_list3 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs4_1 = new ActivatorBindingSite();
            abs_list3.Add(abs4_1);
            Promoter MinPromoter1 = new Promoter();
            MinPromoter1.Enabled = true;
            MinPromoter1.Type = PromoterType.Activated;
            MinPromoter1.Strength = 1;
            MinPromoter1.ActivatorBindSitesList = abs_list3;


            // MinPromoter2 (drugi min promotor s TAL2rep)            
            List<ActivatorBindingSite> abs_list4 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs5_1 = new ActivatorBindingSite();
            abs_list4.Add(abs5_1);
            Promoter MinPromoter2 = new Promoter();
            MinPromoter2.Enabled = true;
            MinPromoter2.Type = PromoterType.Activated;
            MinPromoter2.Strength = 1;
            MinPromoter2.ActivatorBindSitesList = abs_list4;
            


            //---------- GENI ----------//

            // TAL1rep gene pod konst. promotorjem 1
            GeneExpression TAL1rep_Konst_Production1 = new GeneExpression();
            TAL1rep_Konst_Production1.GenePromoter = Promoter1;
            TAL1rep_Konst_Production1.TranscriptionRate = 10;
            TAL1rep_Konst_Production1.TranslationRate = 1;
            TAL1rep_Konst_Production1.mRNADegradationPercent = 0.25;
            TAL1rep_Konst_Production1.ProteinDegradationPercent = 0.1;
            TAL1rep_Konst_Production1.TrDelay = 0;


            // TAL3rep gene pod konst. promotorjem 1
            GeneExpression TAL3rep_Konst_Production1 = new GeneExpression();
            TAL3rep_Konst_Production1.GenePromoter = Promoter1;
            TAL3rep_Konst_Production1.TranscriptionRate = 10;
            TAL3rep_Konst_Production1.TranslationRate = 1;
            TAL3rep_Konst_Production1.mRNADegradationPercent = 0.25;
            TAL3rep_Konst_Production1.ProteinDegradationPercent = 0.1;
            TAL3rep_Konst_Production1.TrDelay = 0;



            // TAL1rep gene pod konst. promotorjem 2
            GeneExpression TAL1rep_Konst_Production2 = new GeneExpression();
            TAL1rep_Konst_Production2.GenePromoter = Promoter2;
            TAL1rep_Konst_Production2.TranscriptionRate = 10;
            TAL1rep_Konst_Production2.TranslationRate = 1;
            TAL1rep_Konst_Production2.mRNADegradationPercent = 0.25;
            TAL1rep_Konst_Production2.ProteinDegradationPercent = 0.1;
            TAL1rep_Konst_Production2.TrDelay = 0;

            // TAL2rep gene pod konst. promotorjem 2
            GeneExpression TAL2rep_Konst_Production2 = new GeneExpression();
            TAL2rep_Konst_Production2.GenePromoter = Promoter2;
            TAL2rep_Konst_Production2.TranscriptionRate = 10;
            TAL2rep_Konst_Production2.TranslationRate = 1;
            TAL2rep_Konst_Production2.mRNADegradationPercent = 0.25;
            TAL2rep_Konst_Production2.ProteinDegradationPercent = 0.1;
            TAL2rep_Konst_Production2.TrDelay = 0;            

            // TAL2rep gene pod konst. promotorjem 3
            GeneExpression TAL2rep_Konst_Production3 = new GeneExpression();
            TAL2rep_Konst_Production3.GenePromoter = Promoter3;
            TAL2rep_Konst_Production3.TranscriptionRate = 10;
            TAL2rep_Konst_Production3.TranslationRate = 1;
            TAL2rep_Konst_Production3.mRNADegradationPercent = 0.25;
            TAL2rep_Konst_Production3.ProteinDegradationPercent = 0.1;
            TAL2rep_Konst_Production3.TrDelay = 0;

            // TAL3rep gene pod konst. promotorjem 3
            GeneExpression TAL3rep_Konst_Production3 = new GeneExpression();
            TAL3rep_Konst_Production3.GenePromoter = Promoter3;
            TAL3rep_Konst_Production3.TranscriptionRate = 10;
            TAL3rep_Konst_Production3.TranslationRate = 1;
            TAL3rep_Konst_Production3.mRNADegradationPercent = 0.25;
            TAL3rep_Konst_Production3.ProteinDegradationPercent = 0.1;
            TAL3rep_Konst_Production3.TrDelay = 0;


            // TAL1rep gene pod min. promotorjem 1
            //      [!!!] OPOMBA: a ne bi moral tole biti TAL3rep, da bi delovalo kot piše v opisu skice?
            GeneExpression TAL1rep_Min_Production = new GeneExpression();
            TAL1rep_Min_Production.GenePromoter = MinPromoter1;
            TAL1rep_Min_Production.TranscriptionRate = 30;              // trojno (3 geni)      -- razlika, če damo 30 vs npr. 90!
            TAL1rep_Min_Production.TranslationRate = 1;
            TAL1rep_Min_Production.mRNADegradationPercent = 0.25;
            TAL1rep_Min_Production.ProteinDegradationPercent = 0.1;
            TAL1rep_Min_Production.TrDelay = 0;

            // TAL3rep gene pod min. promotorjem 1
            GeneExpression TAL3rep_Min_Production = new GeneExpression();
            TAL3rep_Min_Production.GenePromoter = MinPromoter1;
            TAL3rep_Min_Production.TranscriptionRate = 10;
            TAL3rep_Min_Production.TranslationRate = 1;
            TAL3rep_Min_Production.mRNADegradationPercent = 0.25;
            TAL3rep_Min_Production.ProteinDegradationPercent = 0.1;
            TAL3rep_Min_Production.TrDelay = 0;

            // TAL2rep gene pod min. promotorjem 2
            GeneExpression TAL2rep_Min_Production = new GeneExpression();
            TAL2rep_Min_Production.GenePromoter = MinPromoter2;
            TAL2rep_Min_Production.TranscriptionRate = 30;              // trojno (3 geni)      -- razlika, če damo 30 vs npr. 90!
            TAL2rep_Min_Production.TranslationRate = 1;
            TAL2rep_Min_Production.mRNADegradationPercent = 0.25;
            TAL2rep_Min_Production.ProteinDegradationPercent = 0.1;
            TAL2rep_Min_Production.TrDelay = 0;

            // TAL1rep gene pod min. promotorjem 2 
            //  !!!? TAL3rep??
            GeneExpression TAL1rep_Min_Production2 = new GeneExpression();
            TAL1rep_Min_Production2.GenePromoter = MinPromoter2;
            TAL1rep_Min_Production2.TranscriptionRate = 10;
            TAL1rep_Min_Production2.TranslationRate = 1;
            TAL1rep_Min_Production2.mRNADegradationPercent = 0.25;
            TAL1rep_Min_Production2.ProteinDegradationPercent = 0.1;
            TAL1rep_Min_Production2.TrDelay = 0;


            // Reporter1 gene
            GeneExpression Reporter1_Production = new GeneExpression();
            Reporter1_Production.GenePromoter = Promoter1;
            Reporter1_Production.TranscriptionRate = 10;
            Reporter1_Production.TranslationRate = 1;
            Reporter1_Production.mRNADegradationPercent = 0.25;
            Reporter1_Production.ProteinDegradationPercent = 0.1;
            Reporter1_Production.TrDelay = 0;


            // Reporter2 gene
            GeneExpression Reporter2_Production = new GeneExpression();
            Reporter2_Production.GenePromoter = Promoter2;
            Reporter2_Production.TranscriptionRate = 10;
            Reporter2_Production.TranslationRate = 1;
            Reporter2_Production.mRNADegradationPercent = 0.25;
            Reporter2_Production.ProteinDegradationPercent = 0.1;
            Reporter2_Production.TrDelay = 0;


            // Reporter3 gene
            GeneExpression Reporter3_Production = new GeneExpression();
            Reporter3_Production.GenePromoter = Promoter3;
            Reporter3_Production.TranscriptionRate = 10;
            Reporter3_Production.TranslationRate = 1;
            Reporter3_Production.mRNADegradationPercent = 0.25;
            Reporter3_Production.ProteinDegradationPercent = 0.1;
            Reporter3_Production.TrDelay = 0;

            #endregion



            // Zunanji signali - inputi
            int inducer1 = 0;
            int inducer2 = 0;


            #region Simulacija
            //================== SIMULATION ==================//
            for (int current_time = 0; current_time < Globals.SIMULATION_TIME; current_time++)
            {    
                       
                // stanje 1
                if (current_time == 100)
                {
                    inducer1 = 10;
                }
                if (current_time == 120)
                {
                    inducer1 = 0;
                }

                // stanje 2 - inducer1+2                
                if (current_time == 500)
                {
                    inducer1 = 10;
                    inducer2 = 10;
                }
                if (current_time == 520)
                {
                    inducer1 = 0;
                    inducer2 = 0;
                }

                // stanje 3                
                if (current_time == 900)
                {                    
                    inducer2 = 10;
                }                
                if (current_time == 930)
                {                 
                    inducer2 = 0;
                }


                // nazaj stanje1
                if (current_time == 1220)
                {
                    inducer1 = 1;
                }
                if (current_time == 1240)
                {
                    inducer1 = 0;
                }
                


                // Interakcije (represija, aktivacija)                 
                Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL2rep.Count;                
                Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL3rep.Count;                
                Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL1rep.Count;                

                MinPromoter1.ActivatorBindSitesList[0].AmountOfBoundActivator = inducer1;
                MinPromoter2.ActivatorBindSitesList[0].AmountOfBoundActivator = inducer2;


                if (Globals.LIMIT_BINDING_SITE_CAPACITY)
                {
                    Promoter1.LimitAmountOfBoundTF();
                    Promoter2.LimitAmountOfBoundTF();
                    Promoter3.LimitAmountOfBoundTF();

                    MinPromoter1.LimitAmountOfBoundTF();
                    MinPromoter2.LimitAmountOfBoundTF();
                }


                // mRNA production (transcription) & protein production (translation).

                // TAL1rep
                TAL1rep_Konst_Production1.Transcribe(ref TAL1mRNA, current_time);
                TAL1rep_Konst_Production1.DegradeMRNA(ref TAL1mRNA);
                TAL1rep_Konst_Production1.Translate(ref TAL1rep, ref TAL1mRNA, current_time);
                TAL1rep_Konst_Production1.DegradeProtein(ref TAL1rep);

                TAL1rep_Konst_Production2.Transcribe(ref TAL1mRNA, current_time);
                TAL1rep_Konst_Production2.DegradeMRNA(ref TAL1mRNA);
                TAL1rep_Konst_Production2.Translate(ref TAL1rep, ref TAL1mRNA, current_time);
                TAL1rep_Konst_Production2.DegradeProtein(ref TAL1rep);

                TAL1rep_Min_Production2.Transcribe(ref TAL1mRNA, current_time);
                TAL1rep_Min_Production2.DegradeMRNA(ref TAL1mRNA);
                TAL1rep_Min_Production2.Translate(ref TAL1rep, ref TAL1mRNA, current_time);
                TAL1rep_Min_Production2.DegradeProtein(ref TAL1rep);

                // Po uradni skici:
                /*TAL1rep_Min_Production.Transcribe(ref TAL1mRNA, current_time);
                TAL1rep_Min_Production.DegradeMRNA(ref TAL1mRNA);
                TAL1rep_Min_Production.Translate(ref TAL1rep, ref TAL1mRNA, current_time);
                TAL1rep_Min_Production.DegradeProtein(ref TAL1rep);*/

                        // moj popravek: pod MinPromotorjem2 ni TAL1rep ampak TAL3rep
                        TAL1rep_Min_Production.Transcribe(ref TAL3mRNA, current_time);
                        TAL1rep_Min_Production.DegradeMRNA(ref TAL3mRNA);
                        TAL1rep_Min_Production.Translate(ref TAL3rep, ref TAL3mRNA, current_time);
                        TAL1rep_Min_Production.DegradeProtein(ref TAL3rep);




                // TAL2rep
                TAL2rep_Konst_Production2.Transcribe(ref TAL2mRNA, current_time);
                TAL2rep_Konst_Production2.DegradeMRNA(ref TAL2mRNA);
                TAL2rep_Konst_Production2.Translate(ref TAL2rep, ref TAL2mRNA, current_time);
                TAL2rep_Konst_Production2.DegradeProtein(ref TAL2rep);

                TAL2rep_Konst_Production3.Transcribe(ref TAL2mRNA, current_time);
                TAL2rep_Konst_Production3.DegradeMRNA(ref TAL2mRNA);
                TAL2rep_Konst_Production3.Translate(ref TAL2rep, ref TAL2mRNA, current_time);
                TAL2rep_Konst_Production3.DegradeProtein(ref TAL2rep);

                TAL2rep_Min_Production.Transcribe(ref TAL2mRNA, current_time);
                TAL2rep_Min_Production.DegradeMRNA(ref TAL2mRNA);
                TAL2rep_Min_Production.Translate(ref TAL2rep, ref TAL2mRNA, current_time);
                TAL2rep_Min_Production.DegradeProtein(ref TAL2rep);


                // TAL3rep
                TAL3rep_Konst_Production1.Transcribe(ref TAL3mRNA, current_time);
                TAL3rep_Konst_Production1.DegradeMRNA(ref TAL3mRNA);
                TAL3rep_Konst_Production1.Translate(ref TAL3rep, ref TAL3mRNA, current_time);
                TAL3rep_Konst_Production1.DegradeProtein(ref TAL3rep);

                TAL3rep_Konst_Production3.Transcribe(ref TAL3mRNA, current_time);
                TAL3rep_Konst_Production3.DegradeMRNA(ref TAL3mRNA);
                TAL3rep_Konst_Production3.Translate(ref TAL3rep, ref TAL3mRNA, current_time);
                TAL3rep_Konst_Production3.DegradeProtein(ref TAL3rep);

                TAL3rep_Min_Production.Transcribe(ref TAL3mRNA, current_time);
                TAL3rep_Min_Production.DegradeMRNA(ref TAL3mRNA);
                TAL3rep_Min_Production.Translate(ref TAL3rep, ref TAL3mRNA, current_time);
                TAL3rep_Min_Production.DegradeProtein(ref TAL3rep);


                // Reporterji
                Reporter1_Production.Transcribe(ref reporter1_mrna, current_time);
                Reporter1_Production.DegradeMRNA(ref reporter1_mrna);
                Reporter1_Production.Translate(ref reporter1_proteins, ref reporter1_mrna, current_time);
                Reporter1_Production.DegradeProtein(ref reporter1_proteins);

                Reporter2_Production.Transcribe(ref reporter2_mrna, current_time);
                Reporter2_Production.DegradeMRNA(ref reporter2_mrna);
                Reporter2_Production.Translate(ref reporter2_proteins, ref reporter2_mrna, current_time);
                Reporter2_Production.DegradeProtein(ref reporter2_proteins);

                Reporter3_Production.Transcribe(ref reporter3_mrna, current_time);
                Reporter3_Production.DegradeMRNA(ref reporter3_mrna);
                Reporter3_Production.Translate(ref reporter3_proteins, ref reporter3_mrna, current_time);
                Reporter3_Production.DegradeProtein(ref reporter3_proteins);
                


                //========== Capture data/stats and plotting. ==========//                


                // Plotting.
                int x = current_time;
                int ymrna_reporter1 = reporter1_mrna.Count;
                int yreporter1 = reporter1_proteins.Count;
                int ymrna_reporter2 = reporter2_mrna.Count;
                int yreporter2 = reporter2_proteins.Count;
                int ymrna_reporter3 = reporter3_mrna.Count;
                int yreporter3 = reporter3_proteins.Count;
                int yTAL1mRNA = TAL1mRNA.Count;
                int yTAL2mRNA = TAL2mRNA.Count;
                int yTAL3mRNA = TAL3mRNA.Count;
                int yTAL1rep = TAL1rep.Count;
                int yTAL2rep = TAL2rep.Count;
                int yTAL3rep = TAL3rep.Count;


                chart2.Series[0].Points.AddXY(x, yTAL1mRNA);
                chart2.Series[1].Points.AddXY(x, yTAL1rep);

                chart2.Series[2].Points.AddXY(x, yTAL2mRNA);
                chart2.Series[3].Points.AddXY(x, yTAL2rep);

                chart2.Series[4].Points.AddXY(x, yTAL3mRNA);
                chart2.Series[5].Points.AddXY(x, yTAL3rep);

                chart2.Series[10].Points.AddXY(x, ymrna_reporter1);
                chart2.Series[11].Points.AddXY(x, yreporter1);

                chart2.Series[12].Points.AddXY(x, ymrna_reporter2);
                chart2.Series[13].Points.AddXY(x, yreporter2);

                chart2.Series[14].Points.AddXY(x, ymrna_reporter3);
                chart2.Series[15].Points.AddXY(x, yreporter3);

                // Display simulation progress.
                progressBar1.Value = (int)Math.Round(100.0d * (double)(current_time + 1.0d) / (double)Globals.SIMULATION_TIME);
            }

            #endregion


            // Plot display settings (what to display).
            if (checkBoxReporter.Checked)
            {
                chart2.Series[11].Enabled = true; chart2.Series[13].Enabled = true; chart2.Series[15].Enabled = true;
            }
            else
            {
                chart2.Series[11].Enabled = false; chart2.Series[13].Enabled = false; chart2.Series[15].Enabled = false;
            }

            if (checkBoxProtein.Checked)
            {
                chart2.Series[1].Enabled = true; chart2.Series[3].Enabled = true; chart2.Series[5].Enabled = true;
            }
            else
            {
                chart2.Series[1].Enabled = false; chart2.Series[3].Enabled = false; chart2.Series[5].Enabled = false;
            }

            if (checkBoxMRNA.Checked)
            {
                chart2.Series[0].Enabled = true; chart2.Series[2].Enabled = true; chart2.Series[4].Enabled = true;
                chart2.Series[10].Enabled = true; chart2.Series[12].Enabled = true; chart2.Series[14].Enabled = true;
            }
            else
            {
                chart2.Series[0].Enabled = false; chart2.Series[2].Enabled = false; chart2.Series[4].Enabled = false;
                chart2.Series[10].Enabled = false; chart2.Series[12].Enabled = false; chart2.Series[14].Enabled = false;
            }


            /// Write chart data to txt - so you can later use it in MATLAB etc. ///
            if (checkBox1.Checked)
            {
                using (StreamWriter writer = new StreamWriter(textBox6.Text))
                {
                    // Writer reporter1 (Series[11]) data
                    writer.Write("reporter1_x = [");
                    for (int i = 0; i < chart2.Series[11].Points.Count; i++)
                    {
                        writer.Write(chart2.Series[11].Points[i].XValue + " ");
                    }
                    writer.Write("];");

                    writer.WriteLine();
                    writer.WriteLine();

                    writer.Write("reporter1_y = [");
                    for (int i = 0; i < chart2.Series[11].Points.Count; i++)
                    {
                        writer.Write(chart2.Series[11].Points[i].YValues[0] + " ");
                    }
                    writer.Write("];");
                }

            }


            Globals.LAST_RUN_SIMULATION_NAME = "3stable_verzija3";
            Globals.SIMULATION_TIME = 500;
            button10.Enabled = true;
        }




        //========== TRISTABILNO STIKALO, 2 INPUTA, nepovratno 3. stanje, VER. 5 ==========// 
        // url: sigem12.pbworks.com/f/tri%20stanja%20dva%20vhoda-5.png
        private void button11_Click(object sender, EventArgs e)
        {
            Globals.SIMULATION_TIME = 1500;
            button11.Enabled = false;

            #region Plot settings
            // Plot settings            
            chart2.ChartAreas[0].AxisY.LabelStyle.Interval = 100;

            for (int i = 0; i < chart2.Series.Count; i++)
            {
                chart2.Series[i].Points.Clear();
                chart2.Series[i].LegendText = "-";
            }

            chart2.Series[0].LegendText = "TAL1rep mRNA";
            chart2.Series[0].Color = Color.FromArgb(90, 120, 0, 0);
            chart2.Series[0].BorderWidth = 1;
            chart2.Series[0].Points.AddXY(0, 0);

            chart2.Series[1].LegendText = "TAL1rep protein";
            chart2.Series[1].Color = Color.FromArgb(180, 120, 120, 120);
            chart2.Series[1].BorderWidth = 1;
            chart2.Series[1].Points.AddXY(0, 0);

            chart2.Series[2].LegendText = "TAL2rep mRNA";
            chart2.Series[2].Color = Color.FromArgb(90, 0, 100, 0);
            chart2.Series[2].BorderWidth = 1;
            chart2.Series[2].Points.AddXY(0, 0);

            chart2.Series[3].LegendText = "TAL2rep protein";
            chart2.Series[3].Color = Color.FromArgb(180, 0, 100, 0);
            chart2.Series[3].BorderWidth = 1;
            chart2.Series[3].Points.AddXY(0, 0);

            chart2.Series[4].LegendText = "TAL3rep mRNA";
            chart2.Series[4].Color = Color.FromArgb(90, 0, 0, 180);
            chart2.Series[4].BorderWidth = 1;
            chart2.Series[4].Points.AddXY(0, 0);

            chart2.Series[5].LegendText = "TAL3rep protein";
            chart2.Series[5].Color = Color.FromArgb(180, 0, 0, 180);
            chart2.Series[5].BorderWidth = 1;
            chart2.Series[5].Points.AddXY(0, 0);
            
                chart2.Series[6].LegendText = "TAL4rep protein";
                chart2.Series[6].Color = Color.FromArgb(180, 30, 70, 180);
                chart2.Series[6].BorderWidth = 1;
                chart2.Series[6].Points.AddXY(0, 0);

                chart2.Series[7].LegendText = "TAL1akt protein";
                chart2.Series[7].Color = Color.FromArgb(100, 100, 0, 180);
                chart2.Series[7].BorderWidth = 1;
                chart2.Series[7].Points.AddXY(0, 0);

                chart2.Series[8].LegendText = "TAL2akt protein";
                chart2.Series[8].Color = Color.FromArgb(10, 130, 0, 180);
                chart2.Series[8].BorderWidth = 1;
                chart2.Series[8].Points.AddXY(0, 0);

                chart2.Series[9].LegendText = "TAL3akt protein";
                chart2.Series[9].Color = Color.FromArgb(10, 130, 130, 180);
                chart2.Series[9].BorderWidth = 1;
                chart2.Series[9].Points.AddXY(0, 0);

            chart2.Series[10].LegendText = "Reporter1 mRNA";
            chart2.Series[10].Color = Color.FromArgb(120, 255, 0, 0);
            chart2.Series[10].BorderWidth = 1;
            chart2.Series[10].Points.AddXY(0, 0);

            chart2.Series[11].LegendText = "Reporter1 protein";
            chart2.Series[11].Color = Color.FromArgb(205, 255, 0, 0);
            chart2.Series[11].BorderWidth = 2;
            chart2.Series[11].Points.AddXY(0, 0);

            chart2.Series[12].LegendText = "Reporter2 mRNA";
            chart2.Series[12].Color = Color.FromArgb(120, 0, 255, 0);
            chart2.Series[12].BorderWidth = 1;
            chart2.Series[12].Points.AddXY(0, 0);

            chart2.Series[13].LegendText = "Reporter2 protein";
            chart2.Series[13].Color = Color.FromArgb(205, 0, 255, 0);
            chart2.Series[13].BorderWidth = 2;
            chart2.Series[13].Points.AddXY(0, 0);

            chart2.Series[14].LegendText = "Reporter3 mRNA";
            chart2.Series[14].Color = Color.FromArgb(120, 0, 0, 255);
            chart2.Series[14].BorderWidth = 1;
            chart2.Series[14].Points.AddXY(0, 0);

            chart2.Series[15].LegendText = "Reporter3 protein";
            chart2.Series[15].Color = Color.FromArgb(205, 0, 0, 255);
            chart2.Series[15].BorderWidth = 2;
            chart2.Series[15].Points.AddXY(0, 0);
            #endregion


            // Molecules lists
            List<Protein> TAL1rep = new List<Protein>();
            List<Protein> TAL2rep = new List<Protein>();
            List<Protein> TAL3rep = new List<Protein>();
            List<Protein> TAL4rep = new List<Protein>();
            List<Protein> TAL1akt = new List<Protein>();
            List<Protein> TAL2akt = new List<Protein>();
            List<Protein> TAL3akt = new List<Protein>();
            List<Protein> reporter1_proteins = new List<Protein>();
            List<Protein> reporter2_proteins = new List<Protein>();
            List<Protein> reporter3_proteins = new List<Protein>();
            List<Protein> inducer1_proteins = new List<Protein>();
            List<Protein> inducer2_proteins = new List<Protein>();

            List<MRNA> rTAL1mRNA = new List<MRNA>();
            List<MRNA> rTAL2mRNA = new List<MRNA>();
            List<MRNA> rTAL3mRNA = new List<MRNA>();
            List<MRNA> rTAL4mRNA = new List<MRNA>();
            List<MRNA> aTAL1mRNA = new List<MRNA>();
            List<MRNA> aTAL2mRNA = new List<MRNA>();
            List<MRNA> aTAL3mRNA = new List<MRNA>();
            List<MRNA> reporter1_mrna = new List<MRNA>();
            List<MRNA> reporter2_mrna = new List<MRNA>();
            List<MRNA> reporter3_mrna = new List<MRNA>();
            List<MRNA> inducer1_mrna = new List<MRNA>();
            List<MRNA> inducer2_mrna = new List<MRNA>();


            #region Promotorji, geni ...
            //---------- PROMOTORJI ----------//

            // Promoter1 (konstrukt 1 z reporterjem 1)
            List<RepressorBindingSite> rbs_list1 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs1_TAL1 = new RepressorBindingSite();

            List<ActivatorBindingSite> abs_list1 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs1_TAL1 = new ActivatorBindingSite();

            rbs_list1.Add(rbs1_TAL1);
            abs_list1.Add(abs1_TAL1);

            Promoter Promoter1 = new Promoter();
            Promoter1.Enabled = true;
            Promoter1.Type = PromoterType.Activated;
            Promoter1.Strength = 1;
            Promoter1.RepressorBindSitesList = rbs_list1;
            Promoter1.ActivatorBindSitesList = abs_list1;


            // Promoter1 (konstrukt 2 z reporterjem 2)
            List<RepressorBindingSite> rbs_list2 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs2_TAL2 = new RepressorBindingSite();

            List<ActivatorBindingSite> abs_list2 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs2_TAL2 = new ActivatorBindingSite();

            rbs_list2.Add(rbs2_TAL2);
            abs_list2.Add(abs2_TAL2);

            Promoter Promoter2 = new Promoter();
            Promoter2.Enabled = true;
            Promoter2.Type = PromoterType.Activated;
            Promoter2.Strength = 1;
            Promoter2.RepressorBindSitesList = rbs_list2;
            Promoter2.ActivatorBindSitesList = abs_list2;


            // Promoter3 (konstrukt 3 z reporterjem 3)
            List<RepressorBindingSite> rbs_list3 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs3_TAL3 = new RepressorBindingSite();
            RepressorBindingSite rbs3_ind2 = new RepressorBindingSite();

            List<ActivatorBindingSite> abs_list3 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs3_TAL3 = new ActivatorBindingSite();
            ActivatorBindingSite abs3_ind1 = new ActivatorBindingSite();

            rbs_list3.Add(rbs3_TAL3);
            rbs_list3.Add(rbs3_ind2);
            abs_list3.Add(abs3_TAL3);
            abs_list3.Add(abs3_ind1);

            Promoter Promoter3 = new Promoter();
            Promoter3.Enabled = true;
            Promoter3.Type = PromoterType.Activated;
            Promoter3.Strength = 1;
            Promoter3.RepressorBindSitesList = rbs_list3;
            Promoter3.ActivatorBindSitesList = abs_list3;


            // Promoter4 (konstrukt 4)
            List<RepressorBindingSite> rbs_list4 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs4_TAL4 = new RepressorBindingSite();            

            List<ActivatorBindingSite> abs_list4 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs4_TAL4 = new ActivatorBindingSite();
            ActivatorBindingSite abs4_ind1 = new ActivatorBindingSite();

            rbs_list4.Add(rbs4_TAL4);            
            abs_list4.Add(abs4_TAL4);
            abs_list4.Add(abs4_ind1);

            Promoter Promoter4 = new Promoter();
            Promoter4.Enabled = true;
            Promoter4.Type = PromoterType.Activated;
            Promoter4.Strength = 1;
            Promoter4.RepressorBindSitesList = rbs_list4;
            Promoter4.ActivatorBindSitesList = abs_list4;


            // Promoter5 (konstrukt 5)
            List<RepressorBindingSite> rbs_list5 = new List<RepressorBindingSite>();
            RepressorBindingSite rbs5_TAL4 = new RepressorBindingSite();
            RepressorBindingSite rbs5_ind2 = new RepressorBindingSite();

            List<ActivatorBindingSite> abs_list5 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs5_TAL4 = new ActivatorBindingSite();
            
            rbs_list5.Add(rbs5_TAL4);
            rbs_list5.Add(rbs5_ind2);
            abs_list5.Add(abs5_TAL4);            

            Promoter Promoter5 = new Promoter();
            Promoter5.Enabled = true;
            Promoter5.Type = PromoterType.Constitutive;
            Promoter5.Strength = 1;
            Promoter5.RepressorBindSitesList = rbs_list5;
            Promoter5.ActivatorBindSitesList = abs_list5;



            // Promoter6 (konstrukt 6)
            List<RepressorBindingSite> rbs_list6 = new List<RepressorBindingSite>();            
            RepressorBindingSite rbs6_TAL4 = new RepressorBindingSite();

            List<ActivatorBindingSite> abs_list6 = new List<ActivatorBindingSite>();
            ActivatorBindingSite abs6_TAL4 = new ActivatorBindingSite();

            rbs_list6.Add(rbs6_TAL4);            
            abs_list6.Add(abs6_TAL4);

            Promoter Promoter6 = new Promoter();
            Promoter6.Enabled = true;
            Promoter6.Type = PromoterType.Constitutive;
            Promoter6.Strength = 1;
            Promoter6.RepressorBindSitesList = rbs_list6;
            Promoter6.ActivatorBindSitesList = abs_list6;


            //---------- GENI ----------//

            //---------- PROMOTER 1 ----------//
            // TAL2rep (promoter1)
            GeneExpression TAL2rep_pr1 = new GeneExpression();
            TAL2rep_pr1.GenePromoter = Promoter1;
            TAL2rep_pr1.TranscriptionRate = 10;
            TAL2rep_pr1.TranslationRate = 1;
            TAL2rep_pr1.mRNADegradationPercent = 0.25;
            TAL2rep_pr1.ProteinDegradationPercent = 0.15;
            TAL2rep_pr1.TrDelay = 0;

            // TAL3rep (promoter1)
            GeneExpression TAL3rep_pr1 = new GeneExpression();
            TAL3rep_pr1.GenePromoter = Promoter1;
            TAL3rep_pr1.TranscriptionRate = 10;
            TAL3rep_pr1.TranslationRate = 1;
            TAL3rep_pr1.mRNADegradationPercent = 0.25;
            TAL3rep_pr1.ProteinDegradationPercent = 0.15;
            TAL3rep_pr1.TrDelay = 0;

            // TAL1akt (promoter1)
            GeneExpression TAL1akt_pr1 = new GeneExpression();
            TAL1akt_pr1.GenePromoter = Promoter1;
            TAL1akt_pr1.TranscriptionRate = 10;
            TAL1akt_pr1.TranslationRate = 1;
            TAL1akt_pr1.mRNADegradationPercent = 0.25;
            TAL1akt_pr1.ProteinDegradationPercent = 0.15;
            TAL1akt_pr1.TrDelay = 0;

            // Reporter1 (promoter1)
            GeneExpression Reporter1_pr1 = new GeneExpression();
            Reporter1_pr1.GenePromoter = Promoter1;
            Reporter1_pr1.TranscriptionRate = 10;
            Reporter1_pr1.TranslationRate = 1;
            Reporter1_pr1.mRNADegradationPercent = 0.25;
            Reporter1_pr1.ProteinDegradationPercent = 0.15;
            Reporter1_pr1.TrDelay = 0;


            //---------- PROMOTER 2 ----------//
            // TAL1rep (promoter2)
            GeneExpression TAL1rep_pr2 = new GeneExpression();
            TAL1rep_pr2.GenePromoter = Promoter2;
            TAL1rep_pr2.TranscriptionRate = 10;
            TAL1rep_pr2.TranslationRate = 1;
            TAL1rep_pr2.mRNADegradationPercent = 0.25;
            TAL1rep_pr2.ProteinDegradationPercent = 0.15;
            TAL1rep_pr2.TrDelay = 0;

            // TAL3rep (promoter2)
            GeneExpression TAL3rep_pr2 = new GeneExpression();
            TAL3rep_pr2.GenePromoter = Promoter2;
            TAL3rep_pr2.TranscriptionRate = 10;
            TAL3rep_pr2.TranslationRate = 1;
            TAL3rep_pr2.mRNADegradationPercent = 0.25;
            TAL3rep_pr2.ProteinDegradationPercent = 0.15;
            TAL3rep_pr2.TrDelay = 0;

            // TAL2akt (promoter2)
            GeneExpression TAL2akt_pr2 = new GeneExpression();
            TAL2akt_pr2.GenePromoter = Promoter2;
            TAL2akt_pr2.TranscriptionRate = 10;
            TAL2akt_pr2.TranslationRate = 1;
            TAL2akt_pr2.mRNADegradationPercent = 0.25;
            TAL2akt_pr2.ProteinDegradationPercent = 0.15;
            TAL2akt_pr2.TrDelay = 0;

            // Reporter2 (promoter2)
            GeneExpression Reporter2_pr2 = new GeneExpression();
            Reporter2_pr2.GenePromoter = Promoter2;
            Reporter2_pr2.TranscriptionRate = 10;
            Reporter2_pr2.TranslationRate = 1;
            Reporter2_pr2.mRNADegradationPercent = 0.25;
            Reporter2_pr2.ProteinDegradationPercent = 0.15;
            Reporter2_pr2.TrDelay = 0;


            //---------- PROMOTER 3 ----------//
            // TAL1rep (promoter3)
            GeneExpression TAL1rep_pr3 = new GeneExpression();
            TAL1rep_pr3.GenePromoter = Promoter3;
            TAL1rep_pr3.TranscriptionRate = 10;
            TAL1rep_pr3.TranslationRate = 1;
            TAL1rep_pr3.mRNADegradationPercent = 0.25;
            TAL1rep_pr3.ProteinDegradationPercent = 0.15;
            TAL1rep_pr3.TrDelay = 0;

            // TAL2rep (promoter3)
            GeneExpression TAL2rep_pr3 = new GeneExpression();
            TAL2rep_pr3.GenePromoter = Promoter3;
            TAL2rep_pr3.TranscriptionRate = 10;
            TAL2rep_pr3.TranslationRate = 1;
            TAL2rep_pr3.mRNADegradationPercent = 0.25;
            TAL2rep_pr3.ProteinDegradationPercent = 0.15;
            TAL2rep_pr3.TrDelay = 0;

            // TAL4rep (promoter3)
            GeneExpression TAL4rep_pr3 = new GeneExpression();
            TAL4rep_pr3.GenePromoter = Promoter3;
            TAL4rep_pr3.TranscriptionRate = 10;
            TAL4rep_pr3.TranslationRate = 1;
            TAL4rep_pr3.mRNADegradationPercent = 0.25;
            TAL4rep_pr3.ProteinDegradationPercent = 0.15;
            TAL4rep_pr3.TrDelay = 0;

            // TAL3akt (promoter3)
            GeneExpression TAL3akt_pr3 = new GeneExpression();
            TAL3akt_pr3.GenePromoter = Promoter3;
            TAL3akt_pr3.TranscriptionRate = 10;
            TAL3akt_pr3.TranslationRate = 1;
            TAL3akt_pr3.mRNADegradationPercent = 0.25;
            TAL3akt_pr3.ProteinDegradationPercent = 0.15;
            TAL3akt_pr3.TrDelay = 0;

            // Reporter3 (promoter3)
            GeneExpression Reporter3_pr3 = new GeneExpression();
            Reporter3_pr3.GenePromoter = Promoter3;
            Reporter3_pr3.TranscriptionRate = 10;
            Reporter3_pr3.TranslationRate = 1;
            Reporter3_pr3.mRNADegradationPercent = 0.25;
            Reporter3_pr3.ProteinDegradationPercent = 0.15;
            Reporter3_pr3.TrDelay = 0;


            //---------- PROMOTER 4 ----------//            
            // TAL2rep (promoter4)
            GeneExpression TAL2rep_pr4 = new GeneExpression();
            TAL2rep_pr4.GenePromoter = Promoter4;
            TAL2rep_pr4.TranscriptionRate = 10;
            TAL2rep_pr4.TranslationRate = 1;
            TAL2rep_pr4.mRNADegradationPercent = 0.25;
            TAL2rep_pr4.ProteinDegradationPercent = 0.15;
            TAL2rep_pr4.TrDelay = 0;

            // TAL1akt (promoter4)
            GeneExpression TAL1akt_pr4 = new GeneExpression();
            TAL1akt_pr4.GenePromoter = Promoter4;
            TAL1akt_pr4.TranscriptionRate = 10;
            TAL1akt_pr4.TranslationRate = 1;
            TAL1akt_pr4.mRNADegradationPercent = 0.25;
            TAL1akt_pr4.ProteinDegradationPercent = 0.15;
            TAL1akt_pr4.TrDelay = 0;


            //---------- PROMOTER 5 ----------//            
            // TAL1rep (promoter5)
            GeneExpression TAL1rep_pr5 = new GeneExpression();
            TAL1rep_pr5.GenePromoter = Promoter5;
            TAL1rep_pr5.TranscriptionRate = 10;
            TAL1rep_pr5.TranslationRate = 1;
            TAL1rep_pr5.mRNADegradationPercent = 0.25;
            TAL1rep_pr5.ProteinDegradationPercent = 0.15;
            TAL1rep_pr5.TrDelay = 0;

            // TAL2akt (promoter5)
            GeneExpression TAL2akt_pr5 = new GeneExpression();
            TAL2akt_pr5.GenePromoter = Promoter5;
            TAL2akt_pr5.TranscriptionRate = 10;
            TAL2akt_pr5.TranslationRate = 1;
            TAL2akt_pr5.mRNADegradationPercent = 0.25;
            TAL2akt_pr5.ProteinDegradationPercent = 0.15;
            TAL2akt_pr5.TrDelay = 0;


            //---------- PROMOTER 6 ----------//            
            // inducer1 (promoter6)
            GeneExpression inducer1_pr6 = new GeneExpression();
            inducer1_pr6.GenePromoter = Promoter6;
            inducer1_pr6.TranscriptionRate = 10;
            inducer1_pr6.TranslationRate = 1;
            inducer1_pr6.mRNADegradationPercent = 0.25;
            inducer1_pr6.ProteinDegradationPercent = 0.15;
            inducer1_pr6.TrDelay = 0;

            // inducer2 (promoter6)
            GeneExpression inducer2_pr6 = new GeneExpression();
            inducer2_pr6.GenePromoter = Promoter6;
            inducer2_pr6.TranscriptionRate = 10;
            inducer2_pr6.TranslationRate = 1;
            inducer2_pr6.mRNADegradationPercent = 0.25;
            inducer2_pr6.ProteinDegradationPercent = 0.15;
            inducer2_pr6.TrDelay = 0;

            #endregion


            // Zunanji signali - inputi
            int signal1 = 0;
            int signal2 = 0;


            #region Simulacija
            //================== SIMULATION ==================//
            for (int current_time = 0; current_time < Globals.SIMULATION_TIME; current_time++)
            {
                // stanje 1
                if (current_time == 100)
                {
                    signal1 = 1;
                }
                if (current_time == 120)
                {
                    signal1 = 0;
                }

                // stanje 2
                if (current_time == 400)
                {
                    signal2 = 1;
                }
                if (current_time == 420)
                {
                    signal2 = 0;
                }

                // stanje 3
                if (current_time == 700)
                {
                    signal1 = 1;
                    signal2 = 1;
                }
                if (current_time == 800)
                {
                    signal1 = 0;
                    signal2 = 0;
                }

                // poskus prehoda v stanje 1 - ne gre, ker je stanje 3 nepovratno
                if (current_time == 1000)
                {
                    signal1 = 1;                    
                }               

                /*
                if (current_time == 100)
                {
                    signal1 = 1;
                    signal2 = 1;
                }
                if (current_time == 200)
                {
                    signal1 = 0;
                    signal2 = 0;
                }

                if (current_time == 810)    // ne moremo več iz 3. stanja
                {
                    signal2 = 1;                    
                }*/

                //---------- Interakcije ----------//
                
                // Vezava inducerja 1
                if (signal1 > 0)
                {
                    Promoter4.ActivatorBindSitesList[1].AmountOfBoundActivator = inducer1_proteins.Count;
                    Promoter3.ActivatorBindSitesList[1].AmountOfBoundActivator = inducer1_proteins.Count;
                }
                else
                {
                    Promoter4.ActivatorBindSitesList[1].AmountOfBoundActivator = 0;
                    Promoter3.ActivatorBindSitesList[1].AmountOfBoundActivator = 0;
                }


                // Odvezava inducerja 2 od konstrukta 5
                if (signal2 > 0)
                {
                    Promoter5.RepressorBindSitesList[1].AmountOfBoundRepressor = 0;
                    Promoter3.RepressorBindSitesList[1].AmountOfBoundRepressor = 0;
                }
                else
                {
                    Promoter5.RepressorBindSitesList[1].AmountOfBoundRepressor = inducer2_proteins.Count;
                    Promoter3.RepressorBindSitesList[1].AmountOfBoundRepressor = inducer2_proteins.Count;
                }



                Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL1rep.Count;
                Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL2rep.Count;
                Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL3rep.Count;

                Promoter1.ActivatorBindSitesList[0].AmountOfBoundActivator = TAL1akt.Count;
                Promoter2.ActivatorBindSitesList[0].AmountOfBoundActivator = TAL2akt.Count;
                Promoter3.ActivatorBindSitesList[0].AmountOfBoundActivator = TAL3akt.Count;

                Promoter4.RepressorBindSitesList[0].AmountOfBoundRepressor = (int)Math.Round((double)TAL4rep.Count / 3.0d);
                Promoter5.RepressorBindSitesList[0].AmountOfBoundRepressor = (int)Math.Round((double)TAL4rep.Count / 3.0d);
                Promoter6.RepressorBindSitesList[0].AmountOfBoundRepressor = (int)Math.Round((double)TAL4rep.Count / 3.0d);


                if (Globals.LIMIT_BINDING_SITE_CAPACITY)
                {
                    Promoter1.LimitAmountOfBoundTF();
                    Promoter2.LimitAmountOfBoundTF();
                    Promoter3.LimitAmountOfBoundTF();
                    Promoter4.LimitAmountOfBoundTF();
                    Promoter5.LimitAmountOfBoundTF();
                    Promoter6.LimitAmountOfBoundTF();
                }

                /*
                // Promoter1
                if (Promoter1.ActivatorBindSitesList[0].AmountOfBoundActivator <= 0)            // če ni na (1) vezanega aktivatorja, se gor lahko veže represor
                {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL1rep.Count;
                }
                else
                {
                    Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor = 0;
                }

                if (Promoter1.RepressorBindSitesList[0].AmountOfBoundRepressor == 0)
                {
                    Promoter1.ActivatorBindSitesList[0].AmountOfBoundActivator = TAL1akt.Count;
                }
                else
                {
                    Promoter1.ActivatorBindSitesList[0].AmountOfBoundActivator = 0;
                }



                // Promoter2
                if (Promoter2.ActivatorBindSitesList[0].AmountOfBoundActivator == 0) 
                {
                    Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL2rep.Count;
                }
                else
                {
                    Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor = 0;
                }

                if (Promoter2.RepressorBindSitesList[0].AmountOfBoundRepressor == 0)
                {
                    Promoter2.ActivatorBindSitesList[0].AmountOfBoundActivator = TAL2akt.Count;
                }
                else
                {
                    Promoter2.ActivatorBindSitesList[0].AmountOfBoundActivator = 0;
                }


                // Promoter3
                if (Promoter3.ActivatorBindSitesList[0].AmountOfBoundActivator == 0)
                {
                    Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL3rep.Count;
                }
                else
                {
                    Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor = 0;
                }

                if (Promoter3.RepressorBindSitesList[0].AmountOfBoundRepressor == 0)
                {
                    Promoter3.ActivatorBindSitesList[0].AmountOfBoundActivator = TAL3akt.Count;
                }
                else
                {
                    Promoter3.ActivatorBindSitesList[0].AmountOfBoundActivator = 0;
                }*/
                
                // Promoters 4, 5, 6
                //Promoter4.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL4rep.Count;
                //Promoter5.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL4rep.Count;
                //Promoter6.RepressorBindSitesList[0].AmountOfBoundRepressor = TAL4rep.Count;                                           

                //---------- Gene expression ----------//

                // Promoter1
                TAL2rep_pr1.Expression(ref rTAL2mRNA, ref TAL2rep, current_time);
                TAL3rep_pr1.Expression(ref rTAL3mRNA, ref TAL3rep, current_time);
                TAL1akt_pr1.Expression(ref aTAL1mRNA, ref TAL1akt, current_time);
                Reporter1_pr1.Expression(ref reporter1_mrna, ref reporter1_proteins, current_time);
                
                // Promoter2
                TAL1rep_pr2.Expression(ref rTAL1mRNA, ref TAL1rep, current_time);
                TAL3rep_pr2.Expression(ref rTAL3mRNA, ref TAL3rep, current_time);
                TAL2akt_pr2.Expression(ref aTAL2mRNA, ref TAL2akt, current_time);
                Reporter2_pr2.Expression(ref reporter2_mrna, ref reporter2_proteins, current_time);
                
                // Promoter3
                TAL1rep_pr3.Expression(ref rTAL1mRNA, ref TAL1rep, current_time);
                TAL2rep_pr3.Expression(ref rTAL2mRNA, ref TAL2rep, current_time);
                TAL4rep_pr3.Expression(ref rTAL4mRNA, ref TAL4rep, current_time);
                TAL3akt_pr3.Expression(ref aTAL3mRNA, ref TAL3akt, current_time);
                Reporter3_pr3.Expression(ref reporter3_mrna, ref reporter3_proteins, current_time);

                // Promoter4                
                TAL2rep_pr4.Expression(ref rTAL2mRNA, ref TAL2rep, current_time);
                TAL1akt_pr4.Expression(ref aTAL1mRNA, ref TAL1akt, current_time);
                
                // Promoter5
                TAL1rep_pr5.Expression(ref rTAL1mRNA, ref TAL1rep, current_time);
                TAL2akt_pr5.Expression(ref aTAL2mRNA, ref TAL2akt, current_time);

                // Promoter6                
                inducer1_pr6.Expression(ref inducer1_mrna, ref inducer1_proteins, current_time);
                inducer2_pr6.Expression(ref inducer2_mrna, ref inducer2_proteins, current_time);

              
                //========== Capture data/stats and plotting. ==========//                

                // Plotting.
                int x = current_time;
                int ymrna_reporter1 = reporter1_mrna.Count;
                int yreporter1 = reporter1_proteins.Count;
                int ymrna_reporter2 = reporter2_mrna.Count;
                int yreporter2 = reporter2_proteins.Count;
                int ymrna_reporter3 = reporter3_mrna.Count;
                int yreporter3 = reporter3_proteins.Count;

                int yTAL1mRNA = rTAL1mRNA.Count;
                int yTAL2mRNA = rTAL2mRNA.Count;
                int yTAL3mRNA = rTAL3mRNA.Count;
                int yTAL1rep = TAL1rep.Count;
                int yTAL2rep = TAL2rep.Count;
                int yTAL3rep = TAL3rep.Count;


                chart2.Series[0].Points.AddXY(x, yTAL1mRNA);
                chart2.Series[1].Points.AddXY(x, yTAL1rep);

                chart2.Series[2].Points.AddXY(x, yTAL2mRNA);
                chart2.Series[3].Points.AddXY(x, yTAL2rep);

                chart2.Series[4].Points.AddXY(x, yTAL3mRNA);
                chart2.Series[5].Points.AddXY(x, yTAL3rep);

                chart2.Series[10].Points.AddXY(x, ymrna_reporter1);
                chart2.Series[11].Points.AddXY(x, yreporter1);

                chart2.Series[12].Points.AddXY(x, ymrna_reporter2);
                chart2.Series[13].Points.AddXY(x, yreporter2);

                chart2.Series[14].Points.AddXY(x, ymrna_reporter3);
                chart2.Series[15].Points.AddXY(x, yreporter3);

                // Display simulation progress.
                progressBar1.Value = (int)Math.Round(100.0d * (double)(current_time + 1.0d) / (double)Globals.SIMULATION_TIME);
            }

            #endregion


            // Plot display settings (what to display).
            if (checkBoxReporter.Checked)
            {
                chart2.Series[11].Enabled = true; chart2.Series[13].Enabled = true; chart2.Series[15].Enabled = true;
            }
            else
            {
                chart2.Series[11].Enabled = false; chart2.Series[13].Enabled = false; chart2.Series[15].Enabled = false;
            }

            if (checkBoxProtein.Checked)
            {
                chart2.Series[1].Enabled = true; chart2.Series[3].Enabled = true; chart2.Series[5].Enabled = true;
            }
            else
            {
                chart2.Series[1].Enabled = false; chart2.Series[3].Enabled = false; chart2.Series[5].Enabled = false;
            }

            if (checkBoxMRNA.Checked)
            {
                chart2.Series[0].Enabled = true; chart2.Series[2].Enabled = true; chart2.Series[4].Enabled = true;
                chart2.Series[10].Enabled = true; chart2.Series[12].Enabled = true; chart2.Series[14].Enabled = true;
            }
            else
            {
                chart2.Series[0].Enabled = false; chart2.Series[2].Enabled = false; chart2.Series[4].Enabled = false;
                chart2.Series[10].Enabled = false; chart2.Series[12].Enabled = false; chart2.Series[14].Enabled = false;
            }


            /// Write chart data to txt - so you can later use it in MATLAB etc. ///
            if (checkBox1.Checked)
            {
                using (StreamWriter writer = new StreamWriter(textBox6.Text))
                {
                    // Writer reporter1 (Series[11]) data
                    writer.Write("reporter1_x = [");
                    for (int i = 0; i < chart2.Series[11].Points.Count; i++)
                    {
                        writer.Write(chart2.Series[11].Points[i].XValue + " ");
                    }
                    writer.Write("];");

                    writer.WriteLine();
                    writer.WriteLine();

                    writer.Write("reporter1_y = [");
                    for (int i = 0; i < chart2.Series[11].Points.Count; i++)
                    {
                        writer.Write(chart2.Series[11].Points[i].YValues[0] + " ");
                    }
                    writer.Write("];");
                }

            }


            Globals.LAST_RUN_SIMULATION_NAME = "3stable_verzija5";
            Globals.SIMULATION_TIME = 500;
            button11.Enabled = true;
        }



    }
}
